The day debt-ridden Texas oil producer MDC Energy filed for bankruptcy eight months ago, a tank at one of its wells was furiously leaking methane, a potent greenhouse gas, into the atmosphere. As of last week, dangerous, invisible gases were still spewing into the air.

By one estimate, the company would need more than $40 million to clean up its wells if they were permanently closed. But the debts of MDC's parent company now exceed the value of its assets by more than $180 million.

In the months before its bankruptcy filing, though, the company managed to pay its chief executive $8.5 million in consulting fees, its top lender, the French investment bank Natixis, later alleged in bankruptcy court.

Oil and gas companies in the United States are hurtling toward bankruptcy at a pace not seen in years, driven under by a global price war and a pandemic that has slashed demand. And in the wake of this economic carnage is a potential environmental disaster — unprofitable wells that will be abandoned or left untended, even as they continue leaking planet-warming pollutants, and a costly bill for taxpayers to clean it all up.

Still, as these businesses collapse, millions of dollars have flowed to executive compensation.

Whiting Petroleum, a major shale driller in North Dakota that sought bankruptcy protection in April, approved almost $15 million in cash bonuses for its top executives six days before its bankruptcy filing. Chesapeake Energy, a shale pioneer, declared bankruptcy last month, just weeks after it paid $25 million in bonuses to a group of executives. And Diamond Offshore Drilling secured a $9.7 million tax refund under the COVID-19 stimulus bill Congress passed in March, before filing to reorganize in bankruptcy court the next month. Then it won approval from a bankruptcy judge to pay its executives the same amount, as cash incentives.

"It seems outrageous that these executives pay themselves before filing for bankruptcy," said Kathy Hipple, an analyst at the Institute for Energy Economics and Financial Analysis and a finance professor at Bard College. "These are the same managers who ran these companies into bankruptcy to begin with," she said.

The industry's decline may be just beginning. Almost 250 oil and gas companies could file for bankruptcy protection by the end of next year, more than the previous five years combined, according to Rystad Energy, an analytics company. Rystad analysts now expect oil demand will begin falling permanently by decade's end as renewable-energy costs decline, energy efficiency improves, and efforts to fight climate change diminish an industry that has spent the past decade drilling thousands of wells, transforming the U.S. into the biggest oil producer in the world.

The environmental consequences of the industry's collapse would be severe.

Many oil and gas companies are going through Chapter 11 bankruptcy, which allows them to restructure or sometimes lower their debts. The process would not release them from environmental obligations — presuming there is money available to satisfy them.

As MDC Energy's bankruptcy proceeded, so did its methane leak. Texas environmental regulators have issued six violations against MDC at the site related to harmful emissions. An MDC operations manager who spoke on condition of anonymity said he was not allowed to spend money for repairs unless the bankruptcy judge gave permission.

Preliminary estimates this year by researchers examining the immense oil fields of Texas and New Mexico suggest a substantial increase in methane concentrations in March and April of 2020 compared with a year earlier, said Claus Zehner of the SRON Netherlands Institute for Space Research.

"Our explanation is that due to less gas demand, and companies even going bankrupt, there's less maintenance," Zehner said. "And there's more uncontrolled flaring and even more venting," he added, referring to the intentional burning of methane atop towering flares, and the release of methane straight into the atmosphere.

Despite that evidence, the Trump administration is finalizing a plan that would effectively eliminate requirements that oil companies install technology to detect and fix methane leaks from oil and gas facilities.

The wells are already being abandoned across the country. North Dakota, in the heart of fracking country, has gone from zero to 336 so-called abandoned "orphan" wells in just the past two months. In New Mexico, officials have identified 708 orphaned wells.

Companies are legally required to set aside funds to clean up, plug and restore wells and other sites to their original state. But accounting standards give companies wiggle room, experts said.