WASHINGTON — In a surprising victory for President Barack Obama’s environmental legacy, the Senate voted on Wednesday to uphold an Obama-era climate change regulation to control the release of methane from oil and gas wells on public land.

Senators voted 51 to 49 to block consideration of a resolution to repeal the 2016 Interior Department rule to curb emissions of methane, a powerful planet-warming greenhouse gas. Senators John McCain of Arizona, Lindsey Graham of South Carolina and Susan Collins of Maine, all Republicans who have expressed concern about climate change and backed legislation to tackle the issue, broke with their party to join Democrats and defeat the resolution.

The vote also was the first, and probably the only, defeat of a stream of resolutions over the last four months — pursued through the once-obscure Congressional Review Act — to unwind regulations approved late in the Obama administration.

It also could worsen the Trump administration’s problems on Capitol Hill, where there are signs the president’s grip on his party is loosening.