WASHINGTON — A day after President Donald Trump threatened to end protections for so-called Dreamers, he stunned all sides again Wednesday by endorsing a legislative fix that could put the young immigrants on the path to legal status.

Trump appeared eager to cut a deal, embracing a plan that has potential to appeal to Republicans and Democrats. It would combine beefed-up border security with more lasting deportation protections for the nearly 800,000 recipients of the Obama-era Deferred Action for Childhood Arrivals program.

Contours of any emerging agreement remain a work in progress. And Trump, who has shown little hesitation about changing his mind, might do so again, especially if the anti-immigration wing of the Republican Party, led by former adviser Stephen K. Bannon, pressures Congress or Trump to reject any agreement that critics surely will label as amnesty.

But the dire outlook that loomed Tuesday over the young immigrants — sparking an eruption of street protests and an outpouring of public support — lifted somewhat.

"Congress, I really believe, wants to take care of this situation," Trump told reporters on Air Force One. "I'd like to see something where we have good border security, and we have a great DACA transaction where everybody is happy and now they don't have to worry about it anymore."

Absent from the president's remarks was any suggestion of a more substantial immigration overhaul, such as a plan to limit legal migration supported by Bannon, Sen. Tom Cotton, R-Ark., and Attorney General Jeff Sessions, who had promoted such reforms Tuesday when announcing plans to rescind DACA.

Neither was there any mention of border wall funding, an issue Trump had threatened to shut down the government over just a few weeks earlier. Though wall funding still could be included in an eventual deal.

By seeming to move away from those ideas, Trump blindsided many in his own party and left others uncertain whether they can count on the president's support, whether on immigration or any number of issues now facing Congress.

But it also will make it easier for Trump to craft an agreement on border security with Democrats, whose votes will be needed to overcome Republican opposition in Congress to protecting Dreamers.

"Today was a good day in a generally very partisan town," said Senate Minority Leader Charles E. Schumer, D-N.Y. "We are going to fight hard for DACA. We're going to fight hard for the Dream Act. We believe in it. We believe if we keep up the fight, we will succeed."

Trump's comments came after a White House meeting Wednesday morning to discuss the upcoming September agenda in Congress, which included must-pass funding measures and Hurricane Harvey relief.

Republicans left that meeting livid after Trump sided with Democrats to extend government funding and raise the nation's debt ceiling for only three months. The move created the opening Democrats were seeking for swift action on immigration, and Republicans complained it increased their rivals' negotiating leverage.

Republicans already were hesitant to embark on what is sure to be a politically fraught immigration debate without assurance the White House will back them up. Lawmakers will begin their own midterm election campaigns just as the DACA program begins to phase out in March, according to Trump's timetable to rescind the program.

House Speaker Paul D. Ryan said Wednesday he was sympathetic to the Dreamers, but wanted to bolster border security to prevent new illegal arrivals.

"Where does that compromise exist? That's what we're going to spend the next months figuring out," he said. "It's only reasonable and fitting that we also address the root cause of the problem, which is borders that are not sufficiently controlled, while we address this very real and very human problem that's right in front of us."

But Republicans, who have been deadlocked on immigration for years, hope to use Trump's ability to galvanize the GOP base and the growing empathy for Dreamers to win concessions from Democrats on broader border security measures.

Earlier Wednesday, Ryan, engaged in a little pushback against Trump, saying the president needed to be engaged in the process and should clarify what sort of legislation he wanted to see, echoing concerns raised a day earlier by Sen. Marco Rubio, R-Fla., a veteran of past immigration battles.

"We will not be advancing legislation that does not have the support of President Trump, because we're going to work with the president on how to do this legislation," Ryan said.

A few hours later, the president seemed to oblige by providing an outline of what he would like to see.

Congress has no shortage of ideas over how to reform the immigration system. But what leaders have long lacked is a consensus and clear strategy for a legislative package that can muster enough votes.

Even Trump appeared to have second thoughts after Tuesday's announcement to terminate DACA, tweeting later in the evening that he may "revisit" his decision if Congress failed to act.

Such equivocation served only to ease the pressure on Congress. And as seen during the recent collapse of the health care overhaul, this Congress — like many recent ones — has struggled to pass big legislative priorities.

Democrats are skeptical Republicans can deliver their own members' votes on any immigration deal, and initially were unwilling to use the young immigrants as bargaining chips to advance Republican priorities, such as border wall funds, that the GOP majority would not have the votes to pass on its own.

Democrats wanted an immediate vote this month to preserve DACA, and will attach the Dream Act, a long-standing bill that would put the young immigrants on a path to citizenship if they are working, join the military or attend school, to other pending bills before Congress.

But Democrats now might be more willing to negotiate if Trump is at the table and a swift resolution appears in reach.

Lawmakers' own views increasingly have shifted on immigration, even in the few years since Congress last tried — and failed — to approve a sweeping reform package in 2013. Changes in their views are a sign of how much public support has grown for the Dreamers.

Most Democrats now support the Dream Act, even though several opposed it during a failed 2010 effort.

And many Republicans have joined the cause. Almost 20 House Republicans now co-sponsor legislation from Rep. Carlos Curbelo, R-Fla., that would give the young immigrants five-year permits to remain in the U.S. to work or go to school — a turnaround from just a few years ago when even Ryan voted against the Dream Act.

In the Senate, a handful of Republicans publicly have supported a Dream Act-like bill, and more likely would vote for it if it came to a vote. Senate Majority Leader Mitch McConnell has expressed an interest in helping the Dreamers.

Even some of Trump's biggest backers have joined those efforts.

"We have to make it the law of the land," said Rep. Chris Collins of New York, the first House Republican to back Trump for president, who signed on to support the bill on Tuesday after Trump's decision.

Yet many other Republicans side with Trump's more nativist wing of the party, and resist any relief for the young immigrants or other immigrants who are in the country illegally.

"We certainly will oppose any legislation that tries to trade DACA amnesty for enforcement," said Rosemary Jenks, the head of government relations for NumbersUSA, which advocates lower immigration levels. "All this risks another surge."