WASHINGTON — An unexpected meeting of the minds between President Trump and Democratic leaders on Thursday made real a possible deal in Congress to pair enhanced border security with legislation to protect young, undocumented immigrants brought to the country as children.

One day after Mr. Trump hosted Senator Chuck Schumer and Representative Nancy Pelosi for dinner at the White House, the president said he could support legislation to protect the young immigrants known as “Dreamers” from deportation if it were accompanied by a “massive” border security upgrade. Acceding to a key Democratic demand, Mr. Trump said such a package did not need to have funding for a border wall.

It was the second time this month that a tentative agreement announced by Democrats left Republican leaders in Congress scrambling to adjust a legislative agenda that appears increasingly set by the party out of power in the House, the Senate and the White House.

“We’re working on a plan for DACA,” Mr. Trump told reporters, referring to protections for the Deferred Action for Childhood Arrivals program, as he prepared to leave the White House for Florida. He added, “The wall will come later.”