The Portland Pipe Line Corp. filed a federal lawsuit against South Portland on Friday, seeking to overturn the city’s ban on loading crude oil into tankers in Portland Harbor.

The measure, adopted last summer, is aimed at preventing the flow of the South Portland-to-Montreal oil pipeline from being reversed, bringing Canadian oil – and potentially tar sands oil – into Maine.

In the lawsuit, the company – which is joined in challenging the ordinance by a trade association representing tug, towboat and barge operators – alleges that the ordinance interferes with interstate trade, discriminates against Canadian interests, devalues the pipeline and infringes on areas best left to the federal government.

“The ordinance contravenes fundamental principles upon which our Republic was founded,” says the lawsuit, filed in U.S. District Court.

South Portland City Manager James Gailey declined to comment Friday on the merits of the lawsuit. He said the city has contacted the Maine Municipal Association, which insures many towns and cities against lawsuits, and expected that the association would arrange for a law firm to defend the city.

The ordinance was adopted in July, eight months after South Portland voters rejected a referendum that would have allowed only the unloading of oil in South Portland. Reversing the flow of the pipeline would mean tankers and barges could load oil from the pipeline in Portland and take it, via tankers and barges, to other ports and refineries.

Opponents said that could increase the risk of spills and also would require the construction of smokestacks next to Bug Light Park to burn off gases associated with loading diluted bitumen – otherwise known as tar sands oil – from the pipeline onto tankers.

Portland Pipe Line had insisted through much of the process that it had no contracts and no plans to reverse the flow of the pipeline. The company and other opponents of the ordinance also said that proponents of the ban on loading oil from Canada in South Portland were exaggerating the environmental risks.

But the suit’s filing comes against a backdrop of changes in energy markets that are threatening the viability of the South Portland-Montreal pipeline. Those changes have led to steep declines in the volume of crude oil pumped through the pipeline.

The drop in volume could accelerate this year when a project is completed to reverse an existing Canadian pipeline and pump oil from fields in western Canada to refineries in Ontario and Quebec. That means those refineries would no longer need the oil pumped to Canada from Maine.

Reversing the flow of the South Portland-Montreal pipeline to ship western Canada crude for export through Portland Harbor is the most likely way for the pipeline to remain viable, petroleum industry analyst John Auers told the Press Herald in September.

The pipeline company has tried to highlight its economic impact in South Portland, saying it provides 35 jobs, $3.5 million in spending related to tanker docking and other services, $1 million in local property taxes and $2 million in state income taxes. It has pitted its fight against the ordinance as an effort to preserve a working waterfront in South Portland.

The lawsuit says the ordinance seeks to upend the international flow of oil products “based on antipathy for products derived from oil sands.” It describes a somewhat tortured process by South Portland officials to come up with a way to block the potential flow of tar sands oil and finally settling on a method that focused on the possibility of air pollution related to loading the crude oil onto tankers.

But, the lawsuit contends, South Portland has trampled on laws that allow federal officials to regulate pipelines, shipping and trade rules.

“One city in Maine cannot impede federal decision-making on international relations, trade and resource transportation and replace it with its own foreign policy,” the suit said.

Proponents of the ordinance said they expected the measure to be challenged by oil interests.

“I’m saddened, but not totally surprised,” said Judith Moll.

Mary-Jane Ferrier said she expected the company to file a lawsuit, given the industry’s resources.

“They’ve got more money than God, but we’ve got a very good case here in South Portland,” she said. “It’s a strong ordinance.”

A message left for Tom Hardison, the president of the pipeline company, was not returned Friday night.