“I have a great heart for the folks we’re talking about — a great love for them,” he said. “And people think in terms of children, but they’re really young adults. I have a love for these people, and hopefully now Congress will be able to help them and do it properly.”

Under the program enacted by President Barack Obama in 2012, in the midst of an election year, immigrants who were brought to the United States illegally before age 16, have lived here for at least five years, were in school, had graduated from high school or were military veterans and had clean criminal records would be shielded from deportation and eligible for renewable two-year permits to work legally. About 800,000 stood to benefit, and were labeled “dreamers” after the name of the “Dream Act” legislation meant to help them.

To create the program, Mr. Obama relied on an expansive interpretation of his executive power because Congress had failed to pass the Dream Act. Critics, including Mr. Sessions, then a senator, and his onetime aide, Stephen Miller, now a policy adviser to Mr. Trump, argued that Mr. Obama did not have the authority to single-handedly rewrite the law. Mr. Trump accepted that argument after a number of state attorneys general threatened to ask a court to invalidate the program.

In phasing out the program over six months, instead of ending it immediately, Mr. Trump effectively challenged Congress to step in and save it by creating a hard deadline. The message Mr. Trump posted on Twitter on Tuesday evening vowing to revisit the matter if Congress did not do so, however, left many involved in the issue scratching their heads.

Republican congressional aides said that it was not helpful because it undercut the incentive for Congress to act while also putting Mr. Trump at odds with many lawmakers from his own party, including House Speaker Paul D. Ryan, who have said the president does not have authority to revisit it.