WASHINGTON -- In a humiliating failure, President Donald Trump and GOP leaders yanked their bill to repeal "Obamacare" off the House floor Friday when it became clear it would fail badly -- after seven years of nonstop railing against the health care law.

Democrats said Americans can "breathe a sigh of relief." Trump said Obama's law was imploding "and soon will explode."

Thwarted by two factions of fellow Republicans, from the centre and far right, House Speaker Paul Ryan said President Barack Obama's health care law, the GOP's No. 1 target in the new Trump administration, will remain in place "for the foreseeable future."

It was a stunning defeat for the new president after he had demanded House Republicans delay no longer and vote on the legislation Friday, pass or fail.

His gamble failed. Instead Trump, who campaigned as a master deal-maker and claimed that he alone could fix the nation's health care system, saw his ultimatum rejected by Republican lawmakers who made clear they answer to their own voters, not to the president.

He had "never said repeal and replace it in 64 days," a dejected but still combative Trump said at the White House, though he had repeatedly shouted during the presidential campaign that it was going down "immediately."

The bill was withdrawn just minutes before the House vote was to occur, and lawmaker said there were no plans to revisit the issue. Republicans will try to move ahead on other agenda items, including overhauling the tax code, though the failure on the health bill can only make whatever comes next immeasurably harder.

Trump pinned the blame on Democrats.

"With no Democrat support we couldn't quite get there," he told reporters in the Oval Office. "We learned about loyalty, we learned a lot about the vote-getting process."

The Obama law was approved in 2010 with no Republican votes.

Despite reports of backbiting from administration officials toward Ryan, Trump said: "I like Speaker Ryan. ... I think Paul really worked hard."

For his part, Ryan told reporters: "We came really close today but we came up short. ... This is a disappointing day for us." He said the president has "really been fantastic."

But when asked how Republicans could face voters after their failure to make good on years of promises, Ryan quietly said: "It's a really good question. I wish I had a better answer for you."

Last fall, Republicans used the issue to gain and keep control of the White House, Senate and House. During the previous years, they had cast dozens of votes to repeal Obama's law in full or in part, but when they finally got the chance to pass a repeal version that actually had a chance to become law, they couldn't deliver.

Democrats could hardly contain their satisfaction.

"Today is a great day for our country, what happened on the floor is a victory for the American people," said House Minority Leader Nancy Pelosi, who as speaker herself helped Obama pass the Affordable Care Act in the first place. "Let's just for a moment breathe a sigh of relief for the American people."

The outcome leaves both Ryan and Trump weakened politically.

For the president, this piles a big early congressional defeat onto the continuing inquiries into his presidential campaign's Russia connections and his unfounded wiretapping allegations against Obama.

Ryan was not able to corral the House Freedom Caucus, the restive band of conservatives that ousted the previous speaker. Those Republicans wanted the bill to go much further, while some GOP moderates felt it went too far.

Instead of picking up support as Friday wore on, the bill went the other direction, with several key lawmakers coming out in opposition. Rep. Rodney Frelinghuysen of New Jersey, chairman of a major committee, Appropriations, said the bill would raise costs unacceptably on his constituents.

The defections raised the possibility that the bill would not only lose on the floor, but lose big.

The GOP bill would have eliminated the Obama statute's unpopular fines on people who do not obtain coverage and would also have removed the often-generous subsidies for those who purchase insurance.

Republican tax credits would have been based on age, not income like Obama's, and the tax boosts Obama imposed on higher-earning people and health care companies would have been repealed. The bill would have ended Obama's Medicaid expansion and trimmed future federal financing for the federal-state program, letting states impose work requirements on some of the 70 million beneficiaries.

The nonpartisan Congressional Budget Office said the Republican bill would have resulted in 24 million additional uninsured people in a decade and lead to higher out-of-pocket medical costs for many lower-income and people just shy of age 65 when they would become eligible for Medicare. The bill would have blocked federal payments for a year to Planned Parenthood.

Republicans had never built a constituency for the legislation, and in the end the nearly uniform opposition from hospitals, doctors, nurses, the AARP, consumer groups and others weighed heavily with many members. On the other side, conservative groups including the Koch outfit argued the legislation did not go far enough in uprooting Obamacare.

Ryan made his announcement to lawmakers at a very brief meeting, where he was greeted by a standing ovation in recognition of the support he still enjoys from many lawmakers.

When the gathering broke up, Rep. Greg Walden of Oregon, chairman of the Energy and Commerce Committee that helped write the bill, told reporters: ""We gave it our best shot. That's it. It's done. D-O-N-E done. This bill is dead."

Associated Press writers Matthew Daly, Kevin Freking, Mary Clare Jalonick, Richard Lardner, Stephen Ohlemacher, Vivian Salama, Ricardo Alonso-Zaldivar and Ken Thomas contributed to this report.