WASHINGTON — A nearly two-decade stalemate over the legal status of hundreds of thousands of young immigrants moved closer than ever to resolution Thursday as a president eager for tangible victories proved willing to get one by abandoning a position dear to many of his supporters.

The tentative agreement, worked out over dinner Wednesday night between President Donald Trump and the top two Democrats in Congress, could give legal status to nearly 800,000 so-called Dreamers, people who came to the country illegally as children.

The move came slightly more than a week after Trump announced that he would end an Obama administration program known as Deferred Action for Childhood Arrivals, which provided Dreamers a shield against deportation and permission to work legally in the United States. The agreement would, in effect, enshrine the DACA protections in law in return for increased spending on border security.

Trump’s decision to end DACA had been a major victory for immigration restrictionists, both within his administration and outside it. But Trump, who has repeatedly shown a personal soft spot for the Dreamers, never seemed truly in sync with a willingness to see the young immigrants forced out of the country, despite his own call for their deportation during the presidential campaign.

The president’s decision to negotiate a deal with House Democratic leader Nancy Pelosi of California and Senate Democratic leader Charles Schumer of New York infuriated many of his supporters, leading to cries of betrayal. Trump, however, seemed undeterred.

“People want to see that happen,” Trump told reporters Thursday morning, referring to the deal as he prepared to head to Florida to look at hurricane recovery efforts.

“You have 800,000 young people, brought here, no fault of their own. So we’re working on a plan, we’ll see how it works out. We’re going to get massive border security as part of that. And I think something can happen, we’ll see what happens, but something will happen,” he said.

In addition to Trump’s personal feelings about the Dreamers, Republican members of Congress attributed his sudden outreach to the Democrats to unhappiness over his failure to achieve big legislative goals in the first eight months of his administration.

“He’s very frustrated in how things are not getting done, and he’s talking with the Democrats. What’s he supposed to do?” asked Rep. Lou Barletta, R-Pennsylvania, one of Trump’s earliest supporters in Congress and a longtime foe of illegal immigration. “He didn’t come here to do nothing. He came here to keep his promises.”

Legislation to resolve the issue, known as the Dream Act and championed by Sen. Richard Durbin, D-Illinois, and Rep. Lucille Roybal-Allard, D-California, has been under debate since early in the George W. Bush administration.

Longtime advocates cautioned that the treacherous politics of immigration could still upset the tentative deal.

At least for now, however, Trump’s willingness to back a legalization measure appeared to have broken the logjam in Congress, with even longtime supporters of immigration restriction saying they now viewed the young immigrants as a special case, justifying a legislative solution.

White House officials, siding with Pelosi, said they wanted to see legislation pass before Congress takes a scheduled recess in early October, perhaps forestalling the ability of the restrictionist side of the debate to rally opposition.

The vehemence of that opposition was evident Thursday.

“Amnesty Don … Trump Caves on DACA,” screamed a headline on Breitbart News, the conservative website run by Stephen Bannon, Trump’s former chief strategist.

Throughout the day Thursday, Trump sought to defend himself against charges that he was breaking a promise. Responding to a shouted question as he left the White House about whether he favors “amnesty,” Trump shouted back. “The word is DACA.”

Later in Florida, Trump amplified that defense.

“We’re not looking at citizenship. We’re not looking at amnesty. We’re looking at allowing people to stay here,” he said. “We’re talking about taking care of people, people who were brought here, people who’ve done a good job.”

Trump also talked about the importance of his long-sought wall along the U.S. border with Mexico, but notably did not say that money for it would have to be part of a DACA deal, which Democrats have insisted they would not agree to.

“Very important is the wall. We have to be sure the wall isn’t obstructed,” he said. “It doesn’t have to be here [in the DACA deal], but they can’t obstruct the wall if it’s in a budget or anything else.

“We’ll only do it if we get extreme security, not only surveillance but everything that goes with surveillance,” he said.

Trump said he had briefed House Speaker Paul D. Ryan, R-Wisconsin, and Senate Majority Leader Mitch McConnell, R-Kentucky, on his discussions with the Democratic leaders, calling them both early Thursday. They were “on board,” he said.

McConnell’s office released a statement Thursday morning that offered lukewarm support for the emerging deal.

“As Congress debates the best ways to address illegal immigration through strong border security and interior enforcement, DACA should be part of those discussions. We look forward to receiving the Trump administration’s legislative proposal as we continue our work on these issues,” the statement said.

Ryan insisted talks were just beginning. “There’s no agreement,” he said. “These were discussions.”

In a statement Thursday morning, Pelosi and Schumer said that “there was no final deal, but there was agreement on the following: We agreed that the president would support enshrining DACA protections into law, and encourage the House and Senate to act.

“What remains to be negotiated are the details of border security,” they said, adding that the deal would not include money for the border wall. “The president made clear he intends to pursue (wall funding) at a later time, and we made clear we would continue to oppose it.”

Another potential issue could be whether the legislation would give Dreamers an eventual path toward full citizenship. Pelosi said at a news conference that would be part of the deal. Trump, speaking on his return to Washington, said, “We’re not talking about that. We’re not talking about amnesty at all.”

Among the items the two sides agreed on, Pelosi and Schumer said, were border security measures including new technology, drones, air support, sensor equipment, rebuilding roads along the border and the bipartisan McCaul-Thompson bill, a border security measure that passed the House in July.

Distributed by Tribune Content Agency LLC.