(Adds quotes, background)
By David Morgan and Yasmeen Abutaleb
WASHINGTON, May 4 (Reuters) - The U.S. House of Representatives approved a bill on Thursday to repeal major parts of Obamacare and replace it with a Republican healthcare plan, handing President Donald Trump his biggest legislative victory but setting up a tough fight in the Senate.
With the 217-213 vote, Republicans obtained just enough support to push the legislation through the House, sending it to the Senate for consideration. No Democrats voted for the bill.
The bill's passage represented a step toward fulfilling a top Trump campaign pledge and a seven-year Republican quest to dismantle Democratic former President Barack Obama's signature healthcare law.
But the effort now faces new hurdles in the Senate, where the Republicans have only a 52-seat majority in the 100-seat chamber and where just a few Republican defections could sink the bill.
Thursday's vote was also a political victory for House Speaker Paul Ryan, demonstrating his ability to pull together a fractured Republican caucus after two failed attempts this year to win consensus on the healthcare legislation.
Democrats are hoping that the Republicans' vote to repeal Obamacare will spark a voter backlash in next year's midterm congressional elections.
Some 20 million Americans gained healthcare coverage under Obama's 2010 Affordable Care Act, which has recently gathered support in public opinion polls. But Republicans have long attacked it, seeing the program as government overreach and complaining that it drives up healthcare costs.
The Republican bill, known formally as the American Health Care Act, aims to repeal most Obamacare taxes, including a penalty for not buying health insurance. It would slash funding for Medicaid, the program that provides insurance for the poor, and roll back much of Medicaid's expansion.
Even as lawmakers were voting, Trump announced plans to hold a victory celebration in the White House Rose Garden if the legislation was approved.
"Insurance companies are fleeing ObamaCare - it is dead. Our healthcare plan will lower premiums & deductibles - and be great healthcare!," he said in a tweet as the debate wound up ahead of the vote.
Despite having control of the White House and both chambers of Congress, Republicans have found that overturning Obamacare, - which they have long criticized as government overreach - is politically fraught, in part because of voter fears that many people will lose their health insurance as a result.
As Republicans crossed over the vote threshold to pass the bill, Democrats in the House began singing "Na na, na na na na, hey hey hey, goodbye," a rowdy reference to their belief Republicans will lose in the 2018 midterm elections due to their vote.
One of the central issues in the House debate was the treatment of people with "pre-existing" conditions.
Obamacare prevented insurers from charging those with pre-existing conditions higher rates, a common practice before its implementation. It also required them to cover 10 essential health benefits such as maternity care and prescription drugs.
The Republican bill passed on Thursday would allow states to opt out of those provisions. While insurers could not deny people insurance because of pre-existing conditions, they would be allowed to charge them as much as they want.
In an analysis released on Thursday, healthcare consultancy and research firm Avalere Health said the Republican bill would cover only 5 percent of enrollees with pre-existing conditions in the individual insurance markets.
Obamacare expanded Medicaid, provided income-based tax credits to help the poor buy insurance on individual insurance markets set up by the law, and required everyone to buy insurance or pay a penalty.
Republicans have blamed it for driving up healthcare costs, and argued that their bill would give people more choice and reduce the role of government.
"We can have fair healthcare without trapping everyone in a government-run system dreamed up by central planners," House Majority Leader Kevin McCarthy said in the closing minutes of the debate.
Democrats blasted the bill, saying it would make insurance unaffordable for those who need it most and would leave millions more uninsured. They also accused Republicans of seeking tax cuts for the wealthy, paid for in part by cutting health benefits.
"It's come back like a zombie, even more scary than before," said House Democratic leader Nancy Pelosi, referring to the various versions of the Republican healthcare plan that have been floated in recent weeks.
In a push to pass the bill before members leave on Friday for a week in their home districts, the House voted before the bill was assessed by the non-partisan Congressional Budget Office, which estimates its cost and effect on insurance rolls.
Republicans have said that the bill will be scored by the CBO and other fixes will be made before the Senate votes.
Trump made overturning Obamacare a cornerstone of his 2016 campaign and has been frustrated as two efforts to push a bill through the House failed in the last two months, a reflection of the difficulty of reconciling Republican factions.
Wavering moderate Republicans had worried that the legislation would undo a popular aspect of Obamacare and leave too many people with pre-existing medical conditions unable to afford health coverage.
But the skeptical Republican lawmakers got behind the bill after embracing a compromise proposal to add $8 billion over five years to help cover the cost for people with pre-existing illnesses who could otherwise be priced out of insurance markets.
Nearly every major medical group, including the American Medical Association, American Hospital Association and the AARP, was strongly opposed to the Republican bill and said last-minute amendments further eroded protection for the most vulnerable groups, including the sick and elderly.
Health insurers, such as Anthem Inc, UnitedHealth Group Inc, Aetna Inc and Cigna Corp, have faced months of uncertainty over healthcare's future. So have hospital companies, such as HCA Holdings Inc and Tenet Healthcare Corp.
(Additional reporting by Richard Cowan, Steve Holland, Roberta Rampton, Eric Beech, Eric Walsh and Susan Heavey; Writing by Arshad Mohammed; Editing by Frances Kerry)