SOUTH PORTLAND, Maine — The campaign around the Waterfront Protection Ordinance was bruising, hard fought — and historically expensive.

Campaign spending reports filed Tuesday show spending by four political action groups in the WPO campaign exceeded $800,000. Ordinance opponents outspent proponents by a 4-1 margin, $646,000 to $160,000.

It was a local campaign City Clerk Susan Mooney called the most expensive she has seen in her 12 years on the job. It resulted in the Nov. 5 defeat of the WPO by fewer than 200 votes, 4,453 to 4,261.

If it had passed, the ordinance would have prohibited waterfront equipment upgrades considered necessary to accommodate the transportation of controversial oil sands bitumen — often called tar sands oil — from Canada to the Atlantic Ocean by way of the 236-mile Portland-Montreal Pipe Line.

The pipeline currently transports the less corrosive crude oil in the opposite direction, from South Portland to Canadian refineries. Environmentalists and others wanted the ordinance passed in part because they worried the nearly 70-year-old pipeline would not be able to handle the toxic bitumen, and any leaks could contaminate nearby water bodies for years.

Opponents of the ordinance — who argued it was too broadly written, and would effectively shut down any business hoping to expand or maintain facilities on the South Portland waterfront — spent more than $242,000 in cash, received more than $349,000 in in-kind contributions, and were bolstered by a $55,000 loan from the Maine Energy Marketers Association, which created the political action group Save Our Working Waterfront.

Records filed by MEMA, with Portland Pipe Line Corp. financial officer David Cyr as PAC treasurer, show the group has almost $188,000 in unpaid debts, including more than $123,000 owed to DDC Advocacy, campaign consultants in National Harbor, Md., just outside Washington, D.C.

Bernstein Shur attorney Jim Merrill, who represents Portland Pipe Line Corp., said the debts will be paid.

“The industry is committed to fulfilling its post-campaign obligations, and settling them in a timely fashion,” Merrill said in an email Wednesday.

Supporters of the ordinance spent almost $112,000, and received $56,000 in in-kind contributions. Ordinance advocacy groups included Protect South Portland, Save Bug Light [created by Environment Maine], and the Natural Resources Council of Maine.

Spending records show the NCRM largely contributed to the other advocacy groups.

The last spending records also show the campaigns received significant cash and in-kind boosts in the two weeks before the Nov. 5 election, which allowed them to spend more to get their messages out.

Save Our Working Waterfront received a $15,000 contribution from Irving Oil Corp., $5,000 from Sprague Energy, and almost $24,000 from the Washington, D.C.-based American Petroleum Institute. The contributions and $55,000 MEMA loan account for 47 percent of the cash the group received in the campaign.

Protect South Portland received $10,400 in cash contributions during its last reporting phase from late October, about 20 percent of the $50,300 in cash and loans it received in the campaign.

Robert Sellin of Protect South Portland said the influx of money fit the old saw that people do not pay attention to campaigns until the final 10 days.

“It was a record-breaking issue and it continues to be,” Sellin said Thursday. “It is a credit to our campaign, it wasn’t as though we were doing heavy-duty solicitation. We didn’t hire fundraisers and that sort of thing.”

The largest contributions to Protect South Portland were more than $3,500 from Environment Maine, and almost $4,000 in “unitemized contributions.” Contributions from 25 private citizens were topped by $300 from city resident Linden Pavlov, and included $75 from Jeffrey Preslaff, identified as a trombonist from Winnipeg, Manitoba.

The API remained the largest contributor of in-kind services, supplying more than $50,000 of the recorded $72,000 listed by MEMA in the final recording period. Portland Pipe Line Corp. provided almost $17,000 of in-kind contributions.

Cyr reported more than $48,000 of $161,000 spent by Save Our Working Waterfront went to DDC Advocacy, more than $4,000 was spent on print and radio advertising, and more than $25,000 bought campaign literature.

Save Bug Light also called in outside help, spending $1,150 for phone bank work by the Somerville, Mass.,-based Voter Activation Network, and $1,150 for travel reimbursements.

“Reimbursements were for activists,” said Taryn Hallweaver of Environment Maine. “Environment Maine is part of a network of state-based environmental organizations, and a few organizers from our sister organizations came to help out in the last few days.”

In all, the group spent almost $11,000 in the last two weeks and $15,000 in the entire campaign.

The largest expenditure made by Protect South Portland was $2,200 for T-shirts, paid to Barbara Lane of Norway. The group spent $1,500 for canvassers from the Maine People’s Alliance and almost $15,000 on campaign and operating expenses.