But a key part of the deal, a pledge by Senator Mitch McConnell, Republican of Kentucky and the majority leader, to allow an immigration vote in the coming weeks, sets the stage for a battle over the so-called Dreamers, young undocumented immigrants who were brought to the United States illegally as children.

Lawmakers in the House and Senate are offering drastically different visions of how to resolve their fate. But those on both sides of the debate, as well as advocates for immigrants’ rights, said that ultimately Mr. Trump would need to get involved for the immigration dispute to be settled.

Mr. Trump’s intentions were hard to discern, even as he took time to jab at the Democrats.

“Big win for Republicans as Democrats cave on Shutdown,” the president said on Twitter at 11:30 p.m.

The message continued: “Now I want a big win for everyone, including Republicans, Democrats and DACA,” referring to the Dreamers, “but especially for our Great Military and Border Security. Should be able to get there. See you at the negotiating table!”

The vote in the Senate was lopsided: 81 senators voted to end the shutdown while 18 — two Republicans and the rest of the Democrats and an independent who caucuses with them — sided against the measure. In the House, the vote was 266 to 150, with about three-quarters of Democrats opposed.