WASHINGTON — At the heart of the confrontation that led to a government shutdown lie two weeks of mixed messaging by the president — and two decades of deep-seated acrimony and suspicion between Democrats and Republicans on immigration.

“The Dems just want illegal immigrants to pour into our nation unchecked,” President Trump tweeted Sunday. Senator Mitch McConnell, the Kentucky Republican and majority leader, said his Democratic counterpart, Senator Chuck Schumer of New York, was “playing with all of those lives over the issue of illegal immigration.” A Trump campaign official, Michael Glassner, lauded the president for keeping Americans safe from “evil, illegal immigrants who commit violent crimes against lawful U.S. citizens.”

Those derisive statements and others help explain why Democrats entered into the politically perilous fight. After several fruitless efforts at overhauling the nation’s immigration laws, Democrats simply do not trust Republicans, who control Congress and the White House, to follow through on pledges to protect hundreds of thousands of young undocumented immigrants from deportation unless forced to do so.

From Mr. Trump on down, Republicans have regularly expressed a desire to provide relief and certainty to the so-called Dreamers, those brought into the country illegally at a young age. But Republicans have struggled to produce a remedy that does not provoke an uproar from anti-immigrant elements of their base, leading Democrats to wonder how a bill to grant permanent protection to those immigrants could pass, particularly in the House.

“He promised he loved the Dreamers from his heart, that we would be able to work in a bipartisan way,” Representative Nancy Pelosi of California, the Democratic leader, said Saturday of Mr. Trump. “But he always seems to be pushed back from it.”

Image

President Trump’s shifting positions on immigration have left Democrats like Senator Chuck Schumer, the party’s leader in the Senate, exasperated.CreditPete Marovich for The New York Times

Democrats have other issues with the administration’s spending priorities, but the impasse over the hundreds of thousands of Dreamers covered under the Deferred Action for Childhood Arrivals program, or DACA, is central to the fight. And skepticism over the ability to reach a deal is attributable to the dismal record of Congress and two previous administrations in their efforts to make changes to what virtually all parties agree is a broken immigration system.

During the tenures of both George W. Bush and Barack Obama, some of the most influential dealmakers in the Senate — Edward M. Kennedy, Democrat of Massachusetts, and John McCain, Republican of Arizona, among them — tried repeatedly to forge a compromise that would increase border security and provide a path to legalization for millions of undocumented immigrants.

But public sentiment had shifted among Republicans and their constituents despite the support for an immigration overhaul from the top of the party. The deals either collapsed in the Senate or were never even brought up in the House, where sentiment against anything that could be branded as “amnesty” runs deep.

“It just all blew up and fell apart,” said Senator Johnny Isakson, Republican of Georgia and a participant in bipartisan immigration talks in 2005 who remembered getting bricks for a border wall sent to his office in protest of his effort to forge a deal.

Stymied legislatively, Mr. Obama in 2012 instituted DACA via executive order. Mr. Trump promised to reverse it if elected and he did so, providing a window until March 5 to find a permanent solution. That is what led to the shutdown crisis, with Democrats trying to use their leverage over spending to get an acceptable resolution.

Democrats say that twice in recent weeks and another time last year, Mr. Trump appeared to consent to at least the outlines of an agreement that would provide permanent protection for those immigrants. But then he quickly reversed course upon consultation with the hard-line advisers on immigration who have the president’s ear once Democrats depart.

Mr. Schumer said that in a White House luncheon meeting Friday, he offered significant concessions for the DACA legislation, including a large increase in Pentagon spending as well as an agreement to meet the president’s demand for money for the border wall with Mexico that Democrats had previously refused. Democrats say the White House rejected the proposal hours later, asserting that it did not go far enough to limit the ability of new immigrants to bring in more relatives to live in the United States.

The president’s shifting positions have left Democrats exasperated.

“I essentially agreed to give the president something he has said he wants in exchange for something we both want,” Mr. Schumer said on Sunday.

Republicans say that this situation is different from ones that led to previous immigration failures, and that they are fully committed to negotiating in good faith when the shutdown is ended.

“Now we have a deadline and we have bipartisan willingness to deal with the issue,” said Senator John Cornyn of Texas, the No. 2 Republican. “I think it’s different.”

Both Republicans and Democrats say Mr. Trump’s endorsement of any immigration deal is essential, since it is the only way a sufficient number of House Republicans could be enticed to vote for it under cover of Mr. Trump’s backing.

“That makes it easier for House action,” said Senator Jeff Flake, an Arizona Republican who has been part of the latest round of bipartisan immigration talks. “I think if he finds a way to like it, they can pass it in the House.”

But Mr. Trump’s backing is no guarantee of Republican votes. And even if he does endorse a plan, Republicans worry that he could change his mind at any time.

Senator Tom Cotton, an Arkansas Republican who has been a major impediment to an immigration compromise with Democrats, said Sunday on NBC’s “Meet the Press” that he could not commit to back a proposal simply because the president endorsed it. And some on Capitol Hill believe that Speaker Paul D. Ryan’s leadership post would be in jeopardy if he pushed through an immigration bill that most House Republicans opposed.

In recent months, Republicans suggested that they would hold a strong hand in any funding showdown because Democrats would be reluctant to force a government shutdown over undocumented immigrants. If Democrats did, Republicans figured they would have a strong message to counter with by attacking Democrats as willing to shortchange Americans to help those who entered the country illegally.

They are now aggressively pressing that line of assault. But the message is also provoking new doubts about the sincerity of Republican determination to help Dreamers, muddying an immigration debate that is at the center of the conflict and has confounded Washington for almost 20 years.

A version of this article appears in print on , Section A, Page 14 of the New York edition with the headline: Harsh Words, and History, Muddy Fight in Capital. Order Reprints | Today’s Paper | Subscribe