President Donald Trump. Getty Images/Pool The American Health Care Act passed in the House of Representatives on Thursday in a major win for President Donald Trump and House Speaker Paul Ryan after a series of fits and starts for the bill.

The legislation to overhaul the US healthcare system passed 217 to 213, with 20 Republicans and all Democrats voting against it.

The lead-up and the vote were contentious. After the vote, Democratic representatives chanted, "Na na na na, na na na na, hey hey hey, goodbye," apparently suggesting to their Republican counterparts that their votes would cost them control of the chamber.

GOP representatives also walked out of the Capitol after the vote to chants of "Shame!"

Republican leaders celebrated as they left the House floor.

"As difficult as it was, we never gave up," Rep. Steve Scalise said. "It sets us up to do even bigger things in the future."

Right before the vote, Trump said GOP representatives would come to the White House for a celebration if the bill passed. The president delayed his trip to New York City on Thursday.

"If victorious, Republicans will be having a big press conference at the beautiful Rose Garden of the White House immediately after vote!" Trump tweeted.

The AHCA succeeded after a last-minute amendment on Wednesday night won over some moderate holdouts who had expressed concerns about changes to the bill that experts said would undermine protections for Americans with preexisting conditions.

The House Republicans' victory comes over a month after the original version of the AHCA was yanked from the House floor before a vote after a cohort of moderates and conservatives said they would oppose it.

It now heads to the Senate.