Image copyright Reuters Image caption There were slaps on the back from a triumphant Republican leadership

President Donald Trump has declared Obamacare "dead" after the Republican healthcare bill was narrowly passed by the lower chamber of Congress.

The 217-213 vote marked his first legislative victory and goes some way to keeping a key campaign promise to roll back his predecessor's law.

Democrats say the American Health Care Act will leave millions uninsured.

The bill now heads to the Senate, where Republicans have indicated they will cast it aside and write a new law.

Protesters shouted "Shame on you!" as lawmakers left Capitol Hill after the knife-edge vote.

But there were celebrations moments later on the White House lawn, where the president laid on a reception for Republicans in the House of Representatives.

Media playback is unsupported on your device Media caption Trump's battles with Obamacare - in his own words

Six weeks ago, their healthcare attempts appeared doomed when they did not have enough support to have a vote.

But that bill has undergone several revisions to satisfy both the conservative and moderate wings of the Republican party.

Five big consequences of Trumpcare win

Obamacare v Republican plan compared

"Make no mistake, this is a repeal," said a triumphant Mr Trump in the Rose Garden. Obamacare, he added, was "essentially dead".

"Premiums will be coming down, deductibles will be coming down, but very importantly it's a great plan."

What do Democrats say?

The Democrats think the effect of this bill would be the opposite, stripping insurance from the poor, giving tax breaks to the wealthy and casting doubt on health provisions for the chronically sick.

"Thousands of Americans would die because they would no longer have access to care," said Senator Bernie Sanders.

Image copyright Twitter

Groups representing hospitals and doctors have also expressed concerns about the Republican plan, which they say has yet to be properly assessed.

The ill-fated Republican bill in March would result in 24 million more Americans losing insurance within a decade, the nonpartisan Congressional Budget Office said at the time.

What changed since March?

One amendment added since then to placate conservatives means states can opt out of providing essential benefits such as cancer treatment and emergency room visits.

And when $8bn (£6.2bn) over five years was thrown in towards coverage for sick people who otherwise might face higher costs, several moderate Republicans changed course and backed it.

About 20 million Americans gained healthcare coverage under President Barack Obama's 2010 Affordable Care Act, but Republicans viewed it as an overreach of the federal government and said patients had less choice and higher premiums.

Trump health bill: Winners and losers

Patients tell their Obamacare stories

Image caption The CBO estimate for the earlier plan

The New York attorney general said on Thursday evening that he would challenge the bill in court if it became law, on the basis that it would deny people access to care.

What happens now?

The bill, if it becomes law, would mark a major overhaul in the US health system.

But key elements could be ditched by Republican senators, who have said they will start fresh.

Republican Senator Lisa Murkowski said she would like "a clean slate", while Senator Bob Corker said the current bill has "zero" chance in the Senate.

The party controls the chamber 52-48, meaning it can lose no more than two Republicans in order for it to pass.

If the Senate passes its own bill, the plan then goes back to the House for approval or more negotiations and amendments.

What does it mean for Trump?

Anthony Zurcher, BBC News, Washington

Round one of the battle over Obamacare repeal is in the books. Round two is set to begin, with the opponents more powerful and the obstacles more imposing.

It's worth remembering that passage of the Republican healthcare plan in the House of Representatives was supposed to be the easy part. House Speaker Paul Ryan had a sizeable majority at his disposal and the political tools to reward support and punish transgressions.

Instead the American Health Care Act's long, laborious journey exposed divisions within the Republican Party and the limits in Donald Trump's powers of persuasion. These challenges won't disappear. The fault lines will be put under greater pressure and Mr Trump's skills will be further tested when action heads to the Senate.

Unlike the House, the Republican majority there is narrow, and already some in the party are showing misgivings about the current legislation. Democrats, who have more parliamentary tricks up their sleeves, will attempt to disrupt the process at every turn.

Still, a win is a win. It wasn't pretty. It may not last. But Mr Trump and the Republican House leadership will take it.

What's changed from Obamacare?

New bill repeals the individual mandate requiring those who can afford it to have health insurance

Ditches Obamacare requirement for companies with 50 or more staff to provide insurance coverage for employees.

Keeps element allowing under-26s to stay covered on parents' policies

Enables insurers to charge at least five times as much to older customers.

States can opt out of essential benefits like emergency care and cancer treatment

And they can waive the guarantee to provide healthcare to people with pre-existing conditions.