President Trump and Senator Chuck Schumer of New York, the top Democrat in the Senate, came close to an agreement to avert a government shutdown over lunch on Friday, but their consensus broke down later in the day when the president and his chief of staff demanded more concessions on immigration, according to people on both sides familiar with the lunch and follow-up calls between Mr. Trump and Mr. Schumer.

The negotiations between Mr. Trump and Mr. Schumer, fellow New Yorkers who have known each other for years, began when the president called Mr. Schumer Friday morning, giving the White House staff almost no heads-up. In a lengthy phone conversation, both men agreed to seek a permanent spending deal rather than the stopgap measure being negotiated by lawmakers on Capitol Hill.

Less than an hour later, Mr. Schumer was meeting with Mr. Trump over cheeseburgers in the president’s study next to the Oval Office. The White House chief of staff, John F. Kelly, was there, as was Mr. Schumer’s chief of staff, Mike Lynch.

Read more from Michael D. Shear and Maggie Haberman »

Even as the shutdown dominates headlines, it could be forgotten by November.

In the fall of 2013, Republican hard-liners engineered a 16-day shutdown of the federal government, implausibly insisting that President Barack Obama acquiesce to their demand that the Affordable Care Act be stripped of all funding.

The gambit failed miserably. The Republican Party’s already low standing in public opinion polls plunged further. Mr. Obama and Democratic lawmakers were widely seen as victorious.

Then the following November, something happened that plainly informed the moves of Democrats today as they drove the government toward another shutdown: Voters handed Republicans overwhelming victories and a Senate majority — in large part because of dissatisfaction with the man in the White House. The shutdown was a distant memory.

“I don’t think anybody paid a big price for it,” Senator Joe Manchin III, a West Virginia Democrat who is facing a competitive re-election race this fall, said of the 2014 election.