SOUTH PORTLAND — The city has already spent more than $500,000 defending its controversial Clear Skies ordinance in federal court, and municipal officials expect the cost to reach nearly $1 million when the lawsuit filed by the Portland Pipe Line Corp. goes to trial later this year.

Meanwhile, the city’s Clear Skies Legal Defense Fund has received a little more than $21,500 in donations, disappointing some city officials who expected more from supporters of the ordinance, which bans the export of domestic oil through the city. The pipeline, which has carried foreign crude to Canada for decades, was essentially shut down in recent months because of a lack of demand.

So far, the city has spent $518,513 on legal fees related to the lawsuit – about $375,000 of which has been charged in recent months as lawyers for each side have waded through the costly “discovery phase” leading up to the trial, city officials said.

Last week, the City Council agreed to transfer $500,000 from cash reserves to the legal defense fund, in addition to a similar $200,000 transfer that was made in 2015. In total, the city has set aside $899,567 to defend the ordinance, including donations and $177,945 in this year’s regular legal budget. Only $381,054 remains unspent.

“The longer it takes, the more it’s going to cost,” said Mayor Tom Blake. “We hope for expediency, but it doesn’t look like that’s going to happen. The price to ensure the health of the community, it’s not cheap.”

In particular, Blake said, the city didn’t anticipate the high cost of expert witnesses who have testified during the discovery phase. And the case has the potential to cost a lot more if it goes to the U.S. Supreme Court, as some think it might.

“So much is going on in energy markets right now, we’re paying top dollar for expert witnesses,” Blake said. “I wish we didn’t have to spend a nickel. I’m disappointed it’s taking so long, but I’m not surprised, and we’re at a point now where we can’t turn around.”

Blake has changed his stance since mounting legal costs became a concern in the spring. At that time, Blake said he wasn’t worried because the city is financially healthy, but it should be prepared for a worst-case scenario if the pipeline company wins its lawsuit.

Since the pipeline company sued in February 2015, the city has paid legal fees to its local attorney, Sally Daggett of Jansen Baird Gardner & Henry in Portland, and to Foley Hoag, a prominent Boston law firm with environmental expertise.

Portland Pipe Line operates an underground pipeline that stretches from its terminal in South Portland to Montreal. The pipeline has historically been used to send oil to Canada, but more recently has been eyed as a way to export Canadian crude.

The company is challenging South Portland’s Clear Skies ordinance, passed by the council in July 2014, which banned the loading of crude oil into tankers on the city’s waterfront and effectively blocked the company from reversing the flow of its South Portland-to-Montreal pipeline.

In the lawsuit, the company claims that the ban is unconstitutional because it interferes with interstate trade, discriminates against Canadian interests, devalues the pipeline and infringes on areas of regulation best left to the federal government.

The city is acting “to protect the health and welfare of its residents and visitors and traditional land use authority to promote future development consistent with the comprehensive plan,” according to court documents. The Clear Skies ordinance cites concerns about air pollution associated with the bulk loading of crude oil into tankers.

Environmentalists have argued that exporting the oil would accelerate global climate change, while petroleum industry representatives have said the oil is no more damaging than other crude oil.

Blake acknowledged that the Clear Skies Defense Fund hasn’t drawn the support that some hoped it would, but he noted that it received three $5,000 contributions in recent weeks, from Environment Maine, Environment America and Daniel Zilkha of South Casco.

Blake also said Protect South Portland, a community group that fought for the Clear Skies ordinance, has stepped up fundraising in recent weeks, holding events that raised several hundred dollars each.