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.