Republican senators have narrowly voted to begin debate on legislation that will dismantle Obamacare – a victory for Donald Trump, who has spent the last week cajoling and seemingly even threatening senators to support his party's healthcare bill.

The Senate voted 51-50 on the motion to proceed on a measure that will repeal the Affordable Care Act, otherwise known as Obamacare. Vice President Mike Pence cast the deciding vote.

In the coming days, the Senate will now debate, amend and ultimately vote on a healthcare bill that will overhaul America's healthcare system.

Mr Trump said in a statement that he applauds the upper chamber of Congress "for taking a giant step to end the Obamacare nightmare."

"As this vote shows, inaction is not an option, and now the legislative process can move forward as intended to produce a bill that lowers costs and increases options for all Americans," Mr Trump said. "The Senate must now pass a bill and get it to my desk so we can finally end the Obamacare disaster once and for all."

While the Senate's Republican leadership has succeeded in pushing forward its healthcare bill, it is still uncertain whether Majority Leader Mitch McConnell has enough support to pass legislation that will uproot a pillar of former Democratic President Barack Obama's legacy.

Two senators from his own party – Lisa Murkowski of Alaska and Susan Collins of Maine – defected, and for awhile it seemed that Ron Johnson of Wisconsin was also going to follow suit. Mr Johnson was late to the vote and engaged in a lengthy discussion with Mr McConnell before voting 'yea'.

Arizona Senator John McCain – who was diagnosed with brain cancer earlier this month – was also one of the last to deliver a critical vote in favour of opening up debate on the healthcare bill. When the 80-year-old entered the Senate chamber, he was greeted with applause and a few hugs.

Iran's 'Trumpism' contest Show all 10 1 /10 Iran's 'Trumpism' contest Iran's 'Trumpism' contest A picture taken on July 3, 2017 shows a cartoon of US President Donald J. Trump and First Lady Melania Trump on display at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest An Iranian woman looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest An Iranian woman looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest Iranian cartoonist Hadi Asadi poses for a picture with a trophy and an award next to cartoons of US President Donald J. Trump, at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest Iranians look at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest An Iranian woman looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest Iranian reformist cleric Mahmoud Doaei looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest An Iranian man looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest An Iranian woman looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images Iran's 'Trumpism' contest Iranian reformist cleric Mahmoud Doaei looks at cartoons of US President Donald J. Trump at an exhibition of the Islamic Republic's 2017 International Trumpism cartoon and caricature contest, in the capital Tehran on July 3, 2017. / AFP PHOTO / ATTA KENARE (Photo credit should read ATTA KENARE/AFP/Getty Images) AFP/Getty Images

But following the vote, Mr McCain – with stitches above his left eye where doctors had removed a blood clot – proceeded to blast the Senate's draft healthcare bill.

"I will not vote for this bill as it is today," Mr McCain said, and if it fails "as seems likely", he added, the Senate should go back to the drawing board and consult with Democrats.

Mr McCain urged his colleagues to "stop listening to the bombastic loudmouths" on radio, television and the Internet who rail against compromise. "To hell with them!" he said.

Before the vote, Senate Democratic Leader Charles Schumer told Republicans, "We know that ACA is not perfect, but we also know what you've proposed is much worse".

About 20 million people gained health insurance coverage through Obamacare. But Republicans say that it has driven up premiums and forced consumers to buy insurance they do not want and cannot afford.

Despite consistent criticism of the ACA, Republicans have been unable to agree on what a suitable replacement for the law should look like. Last week, it even appeared that the Senate's Republican leadership could not garner enough support to open up debate on a healthcare bill.