The Peaks Island ferry glides past the Portland Pipe Line Corporation's terminal facility in South Portland in this Feb. 1, 2013, file photo where tankers unload oil bound for Montreal.

A federal judge ruled Friday that a South Portland ordinance banning the bulk loading of crude oil is permissible under the U.S. Constitution.

The decision is a major setback for the company that operates a pipeline between Canada and Maine. It will continue to effectively block the Portland Pipeline Corp. from importing Canadian crude and stands as an unusual victory for a local community locked in a legal battle with the oil industry.

In 2015, the pipeline company sued South Portland over its so-called Clear Skies ordinance, which prevents it from reversing the flow of the pipeline that’s long carried oil north to refineries in Montreal, Quebec.

[Trial over South Portland’s oil pipeline ordinance starts Monday]

On Friday, Judge John Woodcock ruled against the company, which argued that the ordinance violates constitutional protections of interstate and international commerce. He heard the case during a four-day trial in June, after having dismissed the company’s other arguments last year.

South Portland mayor Linda Cohen praised the ruling in a press release sent out Friday evening.

“Faced with the prospect of hundreds of thousands of barrels of crude oil being loaded onto marine tank vessels in the City and threatening the health of the residents and preventing redevelopment of the waterfront, the City Council prohibited this new activity,” Cohen said in the email. “We are pleased that the Court upheld the ordinance.”

Woodcock presented his decision as a “narrow” one that shouldn’t be mistaken for an endorsement of the city’s policy.

“Whether the enactment of a local law that effectively puts a lawful local business out of business is good public policy falls within the aegis of the duly-elected representatives of the citizenry of South Portland,” he wrote in the 92-page ruling. “The court concludes only that the ordinance survives the legal challenges the business has mustered.”

South Portland prohibited the loading of bulk crude oil into ships on its waterfront in 2014, as domestic demand for imported oil was flagging and production in the oil sands of western Canada was ramping up.

[South Portland wins round in court fight over oil pipeline]

Defending the ordinance has cost the city more than $1.5 million in legal bills. The Portland Pipeline Corp. could appeal Woodcock’s ruling.

“We are disappointed with today’s decision. We are closely studying the ruling and considering all available options, including appeal,” read a statement sent out by Jim Merrill, the attorney representing the Portland Pipeline Corp.

BDN writer Emily Burnham contributed to this report.

Follow the Bangor Daily News on Facebook for the latest Maine news.