Crashing on the shoals of Congress marks Mr. Trump’s first true encounter with legislative realities and the realization that a president’s power is less limitless than it appears, particularly in the face of an intransigent voting bloc. Mr. Trump is not used to a hard no — but that was the word of the week.

Before he sent Mr. Mulvaney to Capitol Hill to deliver his message Thursday night, the president met with recalcitrant lawmakers at the White House. Mr. Trump reiterated his veiled threat that Republicans who voted no would be punished by constituents who demand they fulfill their promises to roll back the law. He made clear to members of the House Freedom Caucus during a testy hourlong face-off in the Cabinet Room that they were going to have only one chance to fulfill their vows of repealing and replacing the health law, and this was it, according to people who were in the room.

If Mr. Trump has any advantage in the negotiations, it is his ideological flexibility: He is more interested in a win, or avoiding a loss, than any of the arcane policy specifics of the complicated measure, according to a dozen aides and allies interviewed over the past week who described his mood as impatient and jittery. Already, he has shown that flexibility by going back on campaign promises that no one would lose coverage when the Affordable Care Act was replaced and he would not cut Medicaid.

To Mr. Trump and his team, the health care repeal is a troublesome stepchild. His son-in-law and senior adviser, Jared Kushner, who is vacationing with his family in Aspen this week, has said for days that the bill was a mistake to support. Yet Mr. Trump wants to fulfill his party’s pledge to roll back President Obama’s signature accomplishment, but only as a prelude to building his wall, cutting taxes and pushing his $1 trillion infrastructure package.

But resistance from his own party forced Mr. Ryan to delay the vote — even if he cast it as a take-it-or-leave-it deal.

Until this week, Mr. Trump was slow to recognize the high stakes of the fight, or the implications of losing. He approved the agenda putting health care first late last year, almost in passing, in meetings with Mr. Ryan, Vice President Mike Pence and Reince Priebus, the White House chief of staff.

Staff members agreed on a hasty rollout strategy during weekend meetings earlier this month — with Mr. Pence suggesting that the president maintain distance from the proposal, urging him to refer to the bill as Mr. Ryan’s creation, according to senior Republicans.