The measure skirted through the House by a thin 217-213 vote, as all voting Democrats and a group of mostly moderate Republican holdouts voted no. A defeat would have been politically devastating for President Trump and Speaker Paul Ryan, R-Wis.

Beaten but unbowed, Democrats insisted Republicans will pay at election time for repealing major provisions of the law. They sang the pop song ‘‘Na Na Hey Hey Kiss Him Goodbye’’ to the GOP lawmakers as the end of the voting neared.

WASHINGTON — Relieved Republicans muscled their health care bill through the House Thursday, taking their biggest step toward dismantling the Obama health care overhaul since Donald Trump took office. They won passage only after overcoming their own divisions that nearly sank the measure six weeks ago.


Passage was a product of heavy lobbying by the White House and Republicans leaders, plus late revisions that nailed down the final supporters needed. The bill now faces an uncertain fate in the Senate, where even GOP lawmakers say major changes are likely.

‘‘Many of us are here because we pledged to cast this very vote,’’ Ryan said. He added, ‘‘Are we going to keep the promises that we made, or are we going to falter?’’

Leaders rallied rank-and-file lawmakers at a closed-door meeting early Thursday by playing ‘‘Eye of the Tiger,’’ the rousing 1980s song from the ‘‘Rocky III’’ film.

Republicans have promised to erase President Barack Obama’s law since its 2010 enactment, but this year — with Donald Trump in the White House and in full control of Congress — is their first real chance to deliver. But polls have shown a public distaste for the repeal effort and a gain in popularity for Obama’s statute, and Democrats — solidly opposing the bill — said Republicans would pay a price in next year’s congressional elections.


‘‘You vote for this bill, you’ll have walked the plank from moderate to radical,’’ said House Minority Leader Nancy Pelosi, D-Calif., warning Republicans that voters would punish them. ‘‘You will glow in the dark on this one.’’

The bitter health care battle dominated the Capitol even as Congress prepared to give final approval to a bipartisan $1 trillion measure financing federal agencies through September. The House passed that legislation Wednesday, and certain Senate passage will head off a weekend federal shutdown that both parties preferred to avoid.

Ryan canceled a March vote on the health care bill because disgruntled conservatives said the measure was too meek while GOP moderates said its cuts were too deep.

He abandoned a second attempt for a vote last week. As late as Tuesday The Associated Press counted 21 GOP opponents — one short of the number that would kill the measure if all Democrats voted no.

Over the past few weeks, the measure was revamped to attract most hard-line conservatives and some GOP centrists. In a final tweak, leaders added a modest pool of money to help people with pre-existing medical conditions afford coverage, a concern that caused a near-fatal rebellion among Republicans in recent days.

The bill would eliminate tax penalties in Obama’s law, which has clamped down on people who don’t buy coverage and it erases tax increases in the Affordable Care Act on higher-earning people and the health industry. It cuts the Medicaid program for low-income people and lets states impose work requirements on Medicaid recipients. It transforms Obama’s subsidies for millions buying insurance — largely based on people’s incomes and premium costs — into tax credits that rise with consumers’ ages.


It would retain Obama’s requirement that family policies cover grown children until age 26.

But states could get federal waivers freeing insurers from other Obama coverage requirements. With waivers, insurers could charge people with pre-existing illnesses far higher rates than healthy customers, boost prices for older consumers to whatever they wish and ignore the mandate that they cover specified services like pregnancy care.

The bill would block federal payments to Planned Parenthood for a year, considered a triumph by many anti-abortion Republicans.

GOP candidates including Trump have made repealing Obama’s statute an epitome of their campaign pledges, claiming it’s a failing system that’s leaving people with rising health care costs and less access to care.

Republicans will ‘‘gut Obamacare and rescue the American people,’’ said Rep. Doug Collins, R-Ga.

Democrats defended Obama’s law, one of his crowning domestic achievements, for expanding coverage to 20 million Americans and forcing insurers to offer more generous benefits. They said the GOP measure would toss millions off coverage while delivering tax cuts to the wealthy.

‘‘How can you do this to the American people, how can you do this to the people you represent?’’ asked Rep. Jim McGovern, D-Mass.

The nonpartisan Congressional Budget Office estimated in March that the GOP bill would end coverage for 24 million people over a decade. That office also said the bill’s subsidies would be less generous for many, especially lower-earning and older people not yet 65 and qualifying for Medicare.


A CBO estimate for the cost of latest version of their bill was not ready before the House conducted its vote.

Earlier this week, moderates objected that constituents with pre-existing conditions could effectively be denied coverage by insurers charging them exorbitant premiums.

But GOP leaders seemed to win over a raft of wavering lawmakers after adding $8 billion over five years for state high-risk pools, aimed at helping seriously ill people pay expensive premiums. That was on top of $130 billion already in the bill for states to help customers, though critics said those amounts were insufficient.

The House overwhelmingly approved a second bill that Republicans wrote to snuff out a glaring political liability. The measure would delete language in the health care measure entitling members of Congress and their staffs to Obama’s coverage requirements, even if their home states annul them.