ROCKINGHAM, N.C. — The red is getting redder and the blue is getting bluer.

The special congressional election in North Carolina may have involved just about 190,000 voters, but it showed that the class, racial and regional divides among voters have only hardened since that demographic chasm helped drive President Trump’s election in 2016 and the Democratic rebound in the House in 2018.

Dan Bishop, a Republican state lawmaker, eked out a two-point victory in a historically conservative seat because he improved on his party’s performance with working-class whites in more lightly populated parts of the district. And even though Democrats nominated a Marine veteran, Dan McCready, who highlighted his baptism while serving in Iraq, his gains in Charlotte, the state’s biggest city, were not enough to offset the drop-off he suffered across several hundred miles of sprawling farms and small towns.

The bracing takeaway for Republicans is that their tightening embrace of Mr. Trump and his often demagogic politics is further alienating the upper middle-class voters — many in cities and their suburbs— who once were central to their base. At the same time, the Democrats are continuing to struggle with the working-class whites who once represented a pillar of their own coalition.

The results here in a district stretching from Charlotte to Fayetteville presage a brutal, national campaign that seems destined to become the political equivalent of trench warfare, with the two parties rallying their supporters but clashing over a vanishingly small slice of contested electoral terrain.