“No deal was made last night on DACA,” known as the Deferred Action for Childhood Arrivals, Mr. Trump tweeted before daybreak on Thursday.

President Donald Trump denied on Thursday an assertion by Congress’ top two Democrats that they reached an agreement with him that would preserve protections for young immigrants in the U.S. illegally while providing border security enhancements, but not the Southern wall he has coveted.

“No deal was made last night on DACA,” known as the Deferred Action for Childhood Arrivals, Mr. Trump tweeted before daybreak on Thursday, contracting a characterization of a private White House dinner on Wednesday night by his guests, Sen. Chuck Schumer and House Minority Leader Nancy Pelosi.

“Massive border security would have to be agreed to in exchange for consent. Would be subject to vote,” Mr. Trump said in one of a series of posts to his Twitter account.”

It was a bizarre turn of events for a President who’s been inclined recently to turn to Democrats to jump-start legislative imperatives, and it came just days after Mr. Trump and the Democratic leaders agreed to back a three-month extension of the debt limit in order to speed federal financial assistance to hurricane-ravaged Southern states.

“The WALL, which is already under construction in the form of new renovation of old and existing fences and walls, will continue to be built,” Mr. Trump said in one of Thursday’s stream of tweets. But he also voiced sympathy for the hundreds of thousands of younger immigrants vulnerable to deportation even though they were brought to the United States as toddlers or young children. He had announced last week that his administration was rescinding the DACA program, launched by President Barack Obama, and gave Congress 60 months to address the issue.

“Does anybody really want to throw out good, educated and accomplished young people who have jobs, some serving in the military, really?” he tweeted. “They have been in our country for many years through no fault of their own — brought in by parents at a young age. Plus BIG border security.”

The agreement claimed by Mr. Schumer and Ms. Pelosi represents the latest instance of Mr. Trump ditching his own party to make common cause with the opposition.

“We agreed to enshrine the protections of DACA into law quickly, and to work out a package of border security, excluding the wall, that’s acceptable to both sides,” Ms. Pelosi and Mr. Schumer said in their joint statement.

In response to the White House’s initial dissent to the Democratic statement, Pelosi spokesman Drew Hammill said that “the president was clear he would press for the wall but separate from this agreement.”

Either way, it was the second time in two weeks that Trump cut out Republicans to reach a deal with Ms. Pelosi and Mr. Schumer. A person briefed on the meeting, who demanded anonymity to discuss it, said the deal specifies bipartisan legislation called the DREAM Act that provides eventual citizenship for the young immigrants.

The House’s foremost immigration hardliner, GOP Rep. Steve King of Iowa, made clear that he, for one, was not happy.

Addressing Mr. Trump over Twitter, Mr. King wrote that if the reports were true, “Trump base is blown up, destroyed, irreparable, and disillusioned beyond repair. No promise is credible.”

Earlier Wednesday, during a White House meeting with moderate House members from both parties, Trump had urged lawmakers to come up with a bipartisan solution for the “Dreamers.”

“We don’t want to forget DACA,” Mr. Trump told the members at the meeting. “We want to see if we can do something in a bipartisan fashion so that we can solve the DACA problem and other immigration problems.”

Foreshadowing what was to take place later that evening, Mr. Trump had said he would be open to separating the wall issue from the question of the younger immigrants, as long as the wall got dealt with eventually.

The apparent deal is the latest example of Mr. Trump’s sudden pivot to bipartisanship after months of railing against Democrats as “obstructionist.” He has also urged them to join him in overhauling the nation’s tax code, among other priorities.

Mr. Trump, who was deeply disappointed by Republicans’ failure to make good on years of promises to repeal “Obamacare,” infuriated many in his party last week when he reached a three-month deal with Mr. Schumer and Ms. Pelosi to raise the debt ceiling, keep the government running and speed relief to states affected by recent hurricanes.

“More and more we’re trying to work things out together,” Mr. Trump explained on Wednesday, calling the development a “positive thing” for both parties.

“If you look at some of the greatest legislation ever passed, it was done on a bipartisan manner. And so that’s what we’re going to give a shot,” he said.

The “Kumbaya” moment now appears to extend to the thorny issue of immigration, which has been vexing lawmakers for years. Funding for Mr. Trump’s promised wall had been thought to be a major point of contention between Republicans and Democrats as they attempted to forge a deal yet by Thursday, Mr. Trump was apparently ready to deal even on that issue, the one that most defined his campaign for President last year.