After years of debate, the House voted Thursday to repeal key parts of the Affordable Care Act and replace them with new provisions.
But winning approval for the bill could be even more difficult in the Senate than it has been in the House, where Republican leaders struggled for nearly two months to wrangle enough votes in their caucus to secure its passage.
The bill passed by a vote of 217 to 213, which was one more "yes" vote than was needed for passage.
All 193 Democrats voting opposed the bill. They were joined by 20 Republicans voting "no."
"A lot of us have waited seven years to cast this vote," House Speaker Paul Ryan, R-Wis., said shortly before the voting began. "Many of us are here because we pledged to cast this vote: to repeal and replace Obamacare."
"This bill delivers the promises we have made to the American people," Ryan said.
House Majority Whip Steve Scalise, R-La., told MSNBC shortly before the vote began, "We were elected to do this."
After the vote, protesters outside the Capitol building yelled, "Shame, shame!" at members of Congress walking down the front steps.
The bill — which would dramatically change the way the federal government funds purchases of individual health plans and Medicaid — is expected to dramatically increase the number of people without health insurance if enacted into law.
Thursday's vote came a week after the bill was amended to include a provision that won support from conservative holdouts. That provision would, under certain conditions, undo Obamacare's ban on letting insurers charge people with pre-existing health conditions more for their insurance plans than healthy people.
Moderate Republicans initially blanched at that provision. But on Wednesday a number of them agreed to support the bill after the addition of another amendment that would increase funding designed to reduce the impact of the higher premiums on people with pre-existing conditions. Analysis questions how far that funding may go to cut costs for those Americans.
The bill, known as the American Health Care Act, would remove the Obamacare rule requiring most Americans to have health coverage of some kind.
It also is expected to lead to bigger increases in the premium prices of individual plans over the next two years than would be seen if Obamacare remained in effect. And it would give wealthy Americans a tax break.
Republicans rushed to vote on the bill without first having it analyzed by the nonpartisan Congressional Budget Office, which would have provided estimates of coverage losses, premium effects, and costs to the federal budget. A CBO score on the bill could come next week — and provide opponents of the bill more ammunition against it.
An earlier effort to vote on the bill was aborted in late March when GOP leaders saw that it would fail to win enough support to pass it. Before that failed effort, the CBO projected the bill would lead to 24 million more Americans without health insurance over a decade, and insurance plan premium rates up to 20 percent higher than Obamacare rates would be in 2018 before dropping.
Since then, the legislation has undergone a series of changes designed to attract support from both the conservative and moderate wings of the Republican caucus.
Hours before the House vote, Democratic House leader Nancy Pelosi blasted the bill and the GOP.
"Republicans are again maliciously trying to destroy health care," Pelosi said.
"They have this vote tattooed on them. This is a scar that they will carry," she said.
Indeed, it was fear of repercussions at the ballot box that spooked many Republicans as their leaders urged them to vote for the bill. Polling in March on the original version of the legislation showed that just 17 percent of Americans supported the bill.
That dismal level of support reminded Republicans how Democrats lost control of the House in the 2010 midterm elections after passing the Affordable Care Act that year.
Republicans ever since have vowed to repeal Obamacare. But before November's election of Trump as president, they had been stymied in that effort by President Barack Obama, who could veto any bill that would undo his signature health-care reform law.
Trump on Thursday praised the bill less than an hour before the voting began.
Obamacare has been credited with expanding insurance coverage to about 20 million Americans, and with giving people who have pre-existing health conditions a protection against being denied coverage or charged higher rates by insurers.
The law also established a set of minimum essential health benefits that insurers were required to offer in their plans.
The law accomplished its coverage expansion by subsidizing the purchase of individual health plans for low- and moderate-income earners, expanding Medicaid benefits to more poor adults, and allowing people under age 26 to be covered by their parents' health plans.
Critics have faulted the law on several fronts.
They point to sharply higher insurance premiums in some states for people who don't receive Obamacare subsidies, as well as high deductibles for out-of-pocket health costs for customers of individual plans. They also note that the number of people covered by individual plans is much less than had been originally projected by the CBO.
Many counties in the United States also lack competition among insurers for Obamacare plans. About one-third of U.S. counties have just one insurer offering individual plans.
Many insurers have booked losses on their individual plan business since Obamacare took effect. On Wednesday, the big insurer Aetna said it would exit Virginia's Obamacare market next year, the second time in a month that it had announced a departure from a state next year.
Aetna, which had sold plans in 15 states last year, sold plans in just four states this year. The company said it is still deciding whether to remain in Delaware and Nebraska last year.
In Iowa, one of the states that Aetna will exit, the insurer Medica said Wednesday it may follow suit next year, which would leave residents in 94 of the state's 99 counties with no Obamacare plans to choose from.
Supporters of Obamacare said Congress should work to improve the program, and not exacerbate its problems by slashing the funding for subsidies and Medicaid.