Eager to strike a deal with Democrats to extend deportation reprieves to a group of undocumented immigrants brought to the country as children, Mr. Trump was nonetheless constrained by his own campaign promises to toughen immigration restrictions, and hemmed in by Republican congressional leaders uneasy about lining up behind a mercurial president with a penchant for changing his mind.

As negotiators on Capitol Hill held out hope of a swift agreement that could end the impasse before the weekend was out, the House and the Senate reconvened for a rare Saturday session. The likeliest path to reopening the government is an agreement on a stopgap spending measure that would stretch longer than the few days that Senate Democrats wanted, but shorter than the four weeks that the House approved on Thursday night.

Sarah Huckabee Sanders, the White House press secretary, said on Saturday that the president refused to negotiate on immigration issues until there was a deal to reopen the government.

Referring to Democrats’ insistence that a deal to protect the young immigrants be in hand before they agree to a funding measure, Marc Short, the White House legislative director, told reporters at the White House: “There is nothing in this bill Democrats say they object to, yet it’s like a 2-year-old temper tantrum to say, ‘I’m going to take my toys and go home because I’m upset about something else.’”

In his morning Twitter burst, Mr. Trump said Democrats were prioritizing “illegal immigrants” over American citizens and military personnel, and argued that the only solution to end the dysfunction was to defeat the party in this year’s midterm congressional elections.

“Democrats are far more concerned with Illegal Immigrants than they are with our great Military or Safety at our dangerous Southern Border,” the president said on Twitter. “They could have easily made a deal but decided to play Shutdown politics instead. #WeNeedMoreRepublicansIn18 in order to power through mess!”