WASHINGTON (Reuters) - The U.S. Senate on Wednesday rejected a resolution to revoke an Obama-era rule to limit methane emissions from oil and gas production on federal lands, dealing a blow to President Donald Trump’s efforts to free the drilling industry from what he sees as excessive environmental regulation.

A pumpjack brings oil to the surface in the Monterey Shale, California, in a file photo. REUTERS/Lucy Nicholson

The Congressional Review Act resolution received just 49 votes after Republican leaders scrambled for weeks to secure the 51 needed to pass it. The resolution would have revoked the rule and prevented similar regulations from being introduced.

Getting the Trump administration to repeal the BLM rule had been a top priority of the oil and gas industry. Companies said it was unnecessary, would could cost them tens of thousands of dollars per well and hinder production.

But not all Republicans supported the measure, in part because it would have made regulating methane waste more difficult in the future.

Republican Senator John McCain of Arizona made a surprise vote against the resolution, joining fellow Republicans Lindsey Graham of South Carolina and Susan Collins of Maine in opposition to torpedo it.

“While I am concerned that the BLM rule may be onerous, passage of the resolution would have prevented the federal government, under any administration, from issuing a rule that is ‘similar’,” McCain said in a statement.

He said the Interior Department should issue a new rule on to replace the existing one on methane leaks, which he called a public health and air quality issue.

The rule, finalized by President Barack Obama in his last weeks in office, updated 30-year-old regulations that govern flaring, venting and natural gas leaks from oil and gas production. Obama’s administration said it would preserve up to 41 billion cubic feet (BCF) of natural gas per year that is currently lost to leaks and flaring.

The American Petroleum Institute and other industry groups have said the methane rule is unnecessary because companies have made strides in reducing leaks on their own.

“The rule could impede U.S. energy production while reducing local and federal revenues,” said Erik Milito, API’s Upstream and Industry Operations Group Director.

Members of the Western Energy Alliance, which include Devon Energy , Whiting Petroleum and EOG Resources had also been strongly opposed to the rule.

Environmental groups hailed what they depicted as a rare victory for the environment after several regulatory rollbacks by the Trump administration.

“In recent months, thousands of Americans asked the Senate to stand up for clean air and against the oil lobby, and their efforts were successful today,” said Jamie Williams, president of the Wilderness Society.

The Western Values Project estimated that if the rule had been rescinded, the U.S. Treasury would have lost out on $800 million in lost potential royalties from leaked or vented natural gas over the next decade.

Republican Senator John Barrasso of Wyoming, chairman of the Senate Committee on Environment and Public Works who supported the resolution to kill the rule, called on Interior Secretary Ryan Zinke to act unilaterally to revoke it.