Some of the world’s largest oil companies have been ordered to pay part of a $7.2 billion tab to retire hundreds of aging wells in the Gulf of Mexico that they used to own, capping a case that legal experts say is a harbinger of future battles over cleanup costs.

A federal judge ruled last month that Fieldwood Energy LLC, a privately held company that currently controls the old wells and had sought bankruptcy protection, could pass on hundreds of millions of dollars in environmental liabilities to prior owners and insurers of the wells as part of its reorganization plan.

Exxon Mobil Corp. , BP PLC., Hess Corp. , Royal Dutch Shell PLC and insurance companies had objected to the plan. The dispute, litigated for months in federal bankruptcy court in Houston, centered over who should bear the enormous costs of capping and abandoning wells, primarily in the shallow waters of the Gulf of Mexico where an oil spill could wreak havoc. The companies could still appeal the ruling.

The exact future costs of the cleanup are still unclear, but lawyers for BP estimated its liability could top $300 million, while lawyers for Exxon said its exposure could total as much as $373 million. A group of insurers said they could be on the hook for more than $1 billion.

Possible steps to reduce carbon emissions include the decommissioning of offshore wells and other oil-and-gas infrastructure.

Possible steps to reduce carbon emissions include the decommissioning of offshore wells and other oil-and-gas infrastructure.

Photo: Luke Sharrett/Bloomberg News

For offshore wells—unlike most onshore wells—the Department of the Interior can hold previous operators liable for the cleanup if the current operator is unable to cover the expenses, to avoid taxpayers incurring the costs.

Such fights are likely to become more common in the years ahead as countries aim to reduce carbon emissions to comply with the Paris Climate Agreement, said Jason Bordoff, founding director of Columbia University’s Center for Global Energy Policy. That will result in trillions of dollars in expenses to decommission oil-and-gas infrastructure world-wide, he said.

“Who bears the costs?” he said. “There will be people who want to pass the buck.”

BP and Shell have pledged to reduce their carbon emissions to zero by 2050. To accomplish that, those companies will have to sell off some oil-and-gas wells to get their related emissions off their books, say energy analysts. Shell and BP could look to unload more of their older Gulf of Mexico assets, which have higher carbon emissions intensity than early-life projects, said Mfon Usoro, an analyst at energy consulting firm Wood Mackenzie PLC.

But such asset sales present huge risks for big oil companies because many of the buyers are smaller, privately held firms, like Fieldwood, which may not have the financial wherewithal to bear cleanup costs, Ms. Usoro said. This was Fieldwood’s second bankruptcy in two years.

These smaller companies buy the wells for pennies on the dollar and assume the cleanup expenses in the hope that they can reduce the assets’ cost structure and squeeze out the remaining barrels of oil profitably.

“I’ve always questioned this business model,” said Ms. Usoro. “Are these guys able to take care of the end of life?”

Fieldwood, backed by private-equity firm Riverstone Holdings, said it sought bankruptcy protection after the rapid decline in oil prices in 2020 caused by the global pandemic left it short on cash.

Lawyers for the company said in court papers that its reorganization plan, which will spread older assets in shallow waters across several stand-alone companies and separate most younger wells in the Gulf’s deep waters into a different company, leaves the new companies sufficient money to handle cleanup costs.

“The plan…creates a framework for the decommissioning obligations to be managed in an organized, environmentally safe manner and with no liability imposed on the American taxpayer,” Fieldwood said in court papers.

U.S. Bankruptcy Judge Marvin Isgur said in a hearing last month that it was reasonable for all the companies to bear some of the costs and that the plan was in the best interest of the creditors and the country.

Lawyers and a spokesman for Fieldwood didn’t respond to requests for comment.

The Department of the Interior along with some of the previous well operators, including Chevron Corp. and Apache Corp. , signed off on Fieldwood’s reorganization plan, according to court documents. But Exxon, BP, Hess, Shell, a group of insurers and others argued the new companies created by Fieldwood would be short on cash and doomed to fail, unable to handle the costs of decommissioning the wells and potentially creating an environmental disaster.

Spokespersons for Chevron and Apache said they would honor their cleanup liabilities.

Lawyers and spokespersons for the oil companies and insurers that objected declined to comment or didn’t respond to requests for comment. “The plan fails to formulate any such conditions to ensure the protection of the public’s health and safety, and instead seeks to shift such responsibility to predecessors,” lawyers for BP said in court documents.

Companies that provided surety bonds, often required by regulators for offshore operations to insure cleanup costs and other expenses, argued they could bear the brunt of the costs. Liberty Mutual Insurance Co., Hanover Insurance Group Inc., Travelers Cos. Inc. and XL Specialty Insurance Co.warned in court papers that approving Fieldwood’s plan could have a chilling effect on oil-and-gas insurance.

“There is a high likelihood that sureties will exit the market altogether,” the lawyers for the insurers said in court papers. “This would lead to a crumbling of the oil-and-gas industry, as bonds are required to operate.”

Earlier Video

In an interview with WSJ’s Timothy Puko, U.S. special climate envoy John Kerry explains the roles he’d like to see the private sector and countries play in fighting climate change. (Video published April 21) Photo: Rob Alcaraz/The Wall Street Journal The Wall Street Journal Interactive Edition

Write to Christopher M. Matthews at christopher.matthews@wsj.com