House Speaker Paul Ryan addressed reporters Friday afternoon after Republicans decided to withdraw the American Health Care Act. PBS NewsHour will live stream.

WASHINGTON — In a humiliating setback, President Donald Trump and GOP leaders pulled their “Obamacare” repeal bill off the House floor Friday after it became clear the measure would fail badly.

It was a stunning defeat for the new president after he had demanded House Republicans vote on the legislation Friday, threatening to leave “Obamacare” in place and move on to other issues if the vote failed. The bill was withdrawn minutes before the vote was to occur.

The president’s 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.

President Trump just called me. Still on phone.

"We just pulled it," he tells me. — Robert Costa (@costareports) March 24, 2017

Republicans have spent seven years campaigning against former President Barack Obama’s health care law, and cast dozens of votes to repeal it in full or in part. But when they finally got the chance to pass a repeal bill that actually had a chance to get signed, they couldn’t pull it off.

What happens next is unclear, but the path ahead on other priorities, such as overhauling the tax code, can only grow more daunting.

And Trump is certain to be weakened politically, a big early congressional defeat adding to the continuing inquiries into his presidential campaign’s Russia connections and his unfounded wiretapping allegations against Obama.

The development came on the afternoon of a day when the bill, which had been delayed a day earlier, was supposed to come to a vote, come what may. But instead of picking up support as Friday wore on, the bill went the other direction, with some key lawmakers coming out in opposition.

Congressman Rodney Frelinghuysen of New Jersey, chairman of a major committee, Appropriations, said the bill would raise costs unacceptably on his constituents. Rep. Barbara Comstock of Virginia, a key moderate Republican, and GOP Rep. David Joyce of Ohio also announced “no” votes.

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

In the face of that evidence, and despite insistences from White House officials and Ryan that Friday was the day to vote, leadership pulled back from the brink.

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.

Democrats were uniformly opposed. “This bill is pure greed, and real people will suffer and die from it,” said Rep. Pramila Jayapal of Washington state.

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

READ MORE: White House, in gamble, demands make-or-break health vote

PBS NewsHour will update this story as it develops.