(Recasts first paragraph, adds fresh market reaction, quotes from lawmakers and analyst)
WASHINGTON, July 28 (Reuters) - The seven-year Republican quest to kill Obamacare, a major campaign vow by President Donald Trump, lay in ruins on Friday after the Senate failed to dismantle the healthcare law, with congressional leaders now planning to move on to other matters.
John McCain, the maverick 80-year-old senator and 2008 Republican presidential nominee, cast the deciding vote in the dramatic early-morning showdown on the Senate floor as a bill to repeal key elements of Obamacare was defeated, 51-49.
McCain, who flew back from Arizona this week after being diagnosed with aggressive brain cancer, joined fellow Republicans Susan Collins and Lisa Murkowski in voting with Senate Democrats who were unified against the legislation.
"It's time to move on," Senate Majority Leader Mitch McConnell, whose reputation as a master strategist was diminished, said on the Senate floor after the vote that unfolded at roughly 1:30 a.m. (0530 GMT).
While House of Representatives Speaker Paul Ryan said his fellow Republicans should not give up trying on healthcare, he pointed to other pressing issues that needed attention, including major tax-cut legislation sought by Trump.
"We have so much work still to do, and the House will continue to focus on issues that are important to the American people. At the top of that list is cutting taxes for middle-class families and fixing our broken tax code," Ryan said in a statement.
The Senate's healthcare failure called into question the Republican Party's basic ability to govern even as it controls the White House, Senate and House of Representatives.
Trump has not had a major legislative victory after more than six months in office. He had promised to get major healthcare legislation, tax cuts and a boost in infrastructure spending through Congress in short order.
Also on the legislative agenda are spending bills for the fiscal year that begins Oct. 1 to avoid a government shutdown and raising the U.S. debt limit.
While Ryan was able to secure House passage of a comprehensive bill to gut Obamacare in May, McConnell earlier in the week was unable to win passage of similarly broad healthcare legislation amid intraparty squabbling and competing demands by hard-line conservatives and moderates. In the middle-of-the-night vote, he failed to get even a stripped-down, so-called skinny bill over the finish line.
Killing the Affordable Care Act, Democratic former President Barack Obama's signature domestic policy achievement dubbed Obamacare, has been a passion for Republicans since its enactment in 2010 over their unified opposition, and was a key campaign promise by Trump last year. But they failed to come up with a consensus plan to replace it despite holding all the power in Washington.
For the moment, the Affordable Care Act, which extended health insurance to 20 million people and drove the percentage of uninsured people to historic lows, remains in place and must be run by an administration that is hostile to it.
This leaves health insurers unsure of how long the administration will continue to make billions of dollars in Obamacare payments that help cover out-of-pocket medical expenses for low-income Americans.
On Wall Street, shares of hospitals were mostly higher because of the dwindling prospects for big cuts in the Medicaid insurance program for the poor and disabled. Community Health Systems Inc edged up 0.2 percent, HCA Healthcare Inc gained 0.6 percent and Tenet Healthcare Corp fell 2.3 percent.
Shares of health insurers, which had fought against the bill's proposed repeal of the mandate that Americans obtain insurance, were up. Aetna Inc rose 0.8 percent, Anthem Inc gained 2 percent and Humana Inc rose 1 percent.
Brian Jacobsen, a senior investment strategist at Wells Fargo Funds Management, said the Senate failure suggests "it's a house divided and nothing will get done. That's not necessarily that bad for the markets. The status quo is pretty good. More of the same isn't that bad."
Republicans have long denounced Obamacare - which expanded Medicaid and created online marketplaces for individuals to obtain coverage - as an intrusion by government on people's healthcare decisions.
After the vote, Trump tweeted, "3 Republicans and 48 Democrats let the American people down. As I said from the beginning, let Obamacare implode, then deal. Watch!"
But McCain wrote on Twitter, "Skinny repeal fell short because it fell short of our promise to repeal & replace Obamacare w/ meaningful reform."
Representative Tom Cole, a senior House Republican, said healthcare legislation and repealing Obamacare are "obviously on life support." Cole said that "unless the Senate does something," there is nothing further the House can do on that front.
Republicans tried to take stock of the situation.
"I'm in a foul mood," Republican Representative Steve Womack said, adding that the Senate healthcare failure also complicates the outlook for tax overhaul.
Republican Representative Mo Brooks said McConnell "failed at his job," adding, "If you can't do the job, then we need to try somebody else in the hopes that that person can do the job."
UNCERTAINTY FOR HEALTHCARE INDUSTRY
Health insurers have until September to finalize their 2018 health plans in many Obamacare marketplaces.
Some insurers, including Humana and Aetna, have pulled out of such markets, citing the uncertainty over the payments. Others have raised rates by double digits and said that they will need to raise rates another 20 percent if the uncertainty does not ease. Anthem Inc, which has already left three of the 14 states where it sells Blue Cross Blue Shield plans, said this week it might pull out of more.
Democrats - and some Republicans - said the bill's failure could present an opportunity for the two parties to work together to fix problematic areas of the Obamacare law without repealing it.
Top House Democrat Nancy Pelosi called on House Speaker Ryan to establish a process for moving forward on improving Obamacare, rather than repealing it. Top Senate Democrat Chuck Schumer expressed optimism that the two parties can work together to improve the healthcare system.
"Change it, improve it, but dont just take a knife and try to destroy it and put nothing in its place," Schumer said of Obamacare.
The leading lobby for insurers, America's Health Insurance Plans, said it stood ready to help.
The skinny bill, released just three hours before voting began, would have retroactively repealed Obamacare's penalty on individuals who do not obtain health insurance, repealed for eight years a penalty on certain businesses that do not provide employees with insurance and repealed a tax on medical devices until 2020.
(Reporting by Susan Cornwell and Richard Cowan; Additional reporting by Doina Chiacu, Yasmeen Abutaleb, Rodrigo Campos, Amanda Becker, David Morgan and Eric Walsh; Writing by Will Dunham; Editing by Frances Kerry and Jonathan Oatis)