WASHINGTON — Senator Chuck Schumer had just finished outlining a new Democratic immigration proposal over a working dinner at the White House on Wednesday night when President Trump stopped him with a simple question: What is in it for me?

Mr. Schumer, the schmoozy Senate majority leader, responded with a litany of what he saw as Mr. Trump’s presidential sins, according to two people with direct knowledge of the interaction. Those included pulling out of the Paris climate accord and failing to unequivocally denounce anti-Semitism and racism in the wake of the Charlottesville violence.

The time had come, Mr. Schumer declared as Nancy Pelosi, the top House Democrat, nodded in agreement, for the president to prove himself to Democrats if he wanted to do any big deals.

The Run-Up

The podcast that makes sense of the most delirious stretch of the 2016 campaign.

Mr. Trump has been known to freeze out or tongue-lash critics for far less. Instead, to the surprise of people in the room, he responded positively, if vaguely, and laughed. Then he tucked back into the honey sesame crispy beef, part of the Chinese dinner he had ordered delivered to the White House, evoking the kinds of meals the two men grew up eating — Mr. Schumer in Brooklyn and Mr. Trump in Queens.

For the moment, at least, the kitchen-table approach to congressional deal-making seems to have broken a legislative stalemate, though questions linger about whether the alliance will last beyond two brief negotiations.

But Mr. Schumer, who had engaged in a public feud with Mr. Trump for months, thinks that Democrats — meaning Mr. Schumer himself — seems to have finally figured out a way to exert influence on the president without getting too close to a man most Democratic voters view as unfit to serve.

“He likes us. He likes me, anyway,” Mr. Schumer was overheard saying on the Senate floor on Thursday, adding that he had told the president, “You’re much better off if you can sometimes step right and sometimes step left.”

Moving only in one direction, Mr. Schumer recalled telling Mr. Trump, meant he was “boxed” in.

The Wednesday night meeting, the second act of partisan rapprochement that started with a bipartisan budget deal last week, began with a ho-hum 30-minute discussion on trade that included Gary D. Cohn, director of the National Economic Council, whose rocky relationship with Mr. Trump has stabilized at least temporarily, and the commerce secretary, Wilbur Ross, aides said.

That discussion was inconclusive. It was quickly followed by a detailed back-and-forth on the fate of 800,000 young immigrants who stand to be displaced by the elimination of Deferred Action for Childhood Arrivals, or DACA, which was outlined last week by Attorney General Jeff Sessions. Mr. Trump has expressed concern for those who had no choice in coming to the country, and has struggled with the issue for months, aides say, privately expressing hope that he could find a way out of the political bind.

Mr. Trump — who undercut Mr. Sessions by tweeting at Ms. Pelosi’s urging that those in the DACA program should not worry about deportation during the six-month wind-down period — expressed a strong desire, as he has in public, to conclude a quick deal that would protect the so-called Dreamers.

To sweeten such a deal, Mr. Schumer offered his support for enhanced border security measures, already backed by Republicans and Democrats alike, but said he would pull out of any agreement that included funding for a wall on the Mexican border.

At that point, according to two people familiar with the exchange, one of them who was in the room, Mr. Trump called on his chief of staff, John F. Kelly, the former Homeland Security secretary who has long warned against instability on the southern border.

Mr. Kelly launched into a passionate call for stouter border defenses, including his general support for a beefed-up barrier, offering a remarkably pessimistic view of Mexico’s security situation and political stability.

He likened Mexico, one of the United States’ most important trading and law enforcement partners, to Venezuela under the regime of Hugo Chávez, the former leader, suggesting it was on the verge of a collapse that would have repercussions in the United States, according to two people who attended the meeting.

The meeting ended on a positive note, with both sides agreeing to a framework that included dealing with DACA and funding border security measures.

The negotiations weren’t noteworthy for the policies that were discussed. Many Republicans support some kind of legislative extension of DACA tied to enhanced border security.

It was the politics and optics that mattered. By excluding the House speaker, Paul D. Ryan, and Mitch McConnell, the Senate majority leader, from the dinner, the president was sending the message that he was willing to exclude the leadership of his own party in the interest of scoring fast legislative victories.

As it was breaking up, Mr. Schumer, Ms. Pelosi and the president even agreed to tell the news media that they had made progress toward an agreement that all parties expected to be concluded quickly.

Then everything went haywire, illustrating the difficulties that are likely to lie ahead for Mr. Trump and Mr. Schumer, two tabloid-friendly New Yorkers who have difficulty doing anything, including negotiating a high-stakes deal, away from the cameras.

After leaving the White House, Mr. Schumer claimed that he had reached “an agreement” — an assertion that was quickly rebuffed by the president’s press secretary, Sarah Huckabee Sanders, who said that no final agreement had been agreed upon.

Early Thursday, Mr. Schumer and Ms. Pelosi released a joint statement saying that was what they had meant in the first place.

Mr. Trump wasn’t angry at the two Democrats, but he grasped the need to defend himself from charges that he had sold out his supporters who demanded he fulfill his campaign promises to build a wall. Even as Mr. Trump expressed a more gentle approach on immigration, his top national policy adviser, Stephen Miller, an immigration hard-liner, on Thursday privately pushed an effort to curtail legal immigration in conversations with conservative allies and on Capitol Hill.

“If the Democrats aren’t going to approve it, then we’re not going to do what they want,” Mr. Trump told reporters who shouted questions at him as he returned to the White House after a trip to Florida to view areas hit by Hurricane Irma.

But he quickly backtracked, suggesting that an agreement would take place in stages, with an immediate deal to address DACA and border security, followed, an unspecified time later, by funding for a wall. He made no mention of his vow to force Mexico to pay for it.

“We’re working on a deal for DACA, but a lot has to do with the amount of security. We want very heavy security at the border,” he said.