WASHINGTON — House Republicans made good on their years-long promise Thursday to pass a bill that would repeal and replace the Affordable Care Act, winning narrow passage of controversial legislation to unravel many of the law’s popular consumer protections, do away with the individual mandate, and overhaul the insurance market.

The final tally — 217 to 213 — reflected sharp divisions over the GOP’s proposal, which is a long way from becoming law but still represents a huge victory for House Republican leaders and the Trump administration. The GOP has struggled for months to cobble together legislation that would garner the required 216 votes from its own members.

"This bill delivers on the promises that we have made to the American people," said House Speaker Paul Ryan, R-Wis., at the end of an impassioned floor debate. "A lot of us have been waiting seven years to cast this vote … (and) to rescue people from this collapsing law."

He and other Republicans said the GOP plan would increase competition, lower costs, and return power to the states and to individuals. Keeping Obamacare in place, Ryan said, would mean "even higher premiums, even fewer choices, even more insurance companies pulling out" of the individual market.

Democrats fiercely attacked the GOP plan, saying it would gut consumer protections, increase health care costs, and strip health insurance from the poor and middle class.

"Trumpcare eviscerates essential health benefits," such as maternity care and prescription drug coverage, said House Democratic Leader Nancy Pelosi, D-Calif., "... and guts protections for people with pre-existing conditions."

The bill will now go to the Senate, where Republicans are already split over the measure and Democrats are unified in opposition. Republicans hold a narrow 52-seat majority in the chamber, and they will consider the bill under special budget rules that prevent a filibuster.

Thursday’s vote in the House was hastily scheduled and came after weeks of negotiations, hours of wooing wavering Republicans, and a last-minute sweetener added to the bill: an $8 billion amendment to help patients with pre-existing conditions pay for higher premiums and out-of-pocket costs.

"There's been a lot of drama, a little bit of trauma along the way," said Rep. Tom Cole of Oklahoma, a member of the House GOP leadership. Cole and other Republicans shrugged off questions about whether they were allowing lawmakers enough time to read the bill, debate it, and understand its impact.

“We can’t wait a moment longer than necessary to provide relief,” said Rep. Diane Black, R-Tenn. “Americans are suffering from rising costs. Under Obamacare, the situation is getting worse every day.”

Last-minute amendments to the legislation were only made public late Wednesday night, and GOP pushed ahead with Thursday’s vote without having a full analysis from the Congressional Budget Office. A previous CBO report estimated the bill would reduce the deficit by $150 billion over 10 years and cause an estimated 24 million people to forgo or lose their insurance by 2026.

The current House bill would not fully repeal the 2010 Affordable Care Act, but it would kill major elements of that Democratic law. For example, the American Health Care Act would nix the requirement that most Americans purchase insurance, but it would keep in place a provision allowing younger Americans to stay on their parents' health plans until age 26.

The Republican proposal would repeal the ACA’s tax credits, which are based on income and the cost of health insurance in their local market, and replace those with less generous tax credits based on age. The bill would also phase out Obamacare's Medicaid expansion starting Jan. 1, 2020.

The most contentious element centered on how to deal with patients who have pre-existing conditions, such as cancer, asthma, or diabetes. The Affordable Care Act bars insurance companies from discriminating against those with pre-existing conditions. The GOP bill would weaken that protection by allowing states to seek a waiver for insurance companies to charge people with pre-existing conditions higher premiums than other consumers.

That change prompted a bevy of GOP moderates to shun the measure. To shore up support on Wednesday, GOP leaders and the White House agreed to include the extra $8 billion to help patients with pre-existing health problems. That last-minute amendment won over several crucial votes and gave Republicans momentum heading into Thursday’s vote.

“It protects people with pre-existing conditions and brings premiums down,” said Rep. Tom MacArthur, R-N.Y., a moderate who helped negotiate the final package.