Democratic energy has been on vivid display in a series of special elections since President Trump’s inauguration, including in strongly conservative areas where Republicans usually win elections easily, like Arizona’s Eighth District.

Republicans have fared far worse in recent special congressional elections compared with previous elections. Republican margin of victory Source: Offices of secretaries of state; Associated Press | Note: Data do not include races in which Republican candidates ran unopposed.

In a special House election on Tuesday, Debbie Lesko, a Republican, won the conservative Arizona district. But she won by less than six points, a much closer outcome compared to the victory margin of Trent Franks, who beat his opponent by 37 points in 2016.

In 2016, President Trump won the district in a landslide, but on Tuesday, Republican support dropped in nearly all precincts.

Shift from 2016 presidential election Tucson Phoenix Eighth Congressional District Source: Maricopa County recorder’s office

While Republican candidates like Ms. Lesko have mostly prevailed in the recent special elections, they have been winning by sharply reduced margins.

Congressional seats that Republicans defended easily in 2016 — in Georgia, South Carolina and elsewhere — have barely stayed in Republican hands.

Change in margins of victory for seats that stayed Republican

In one race, Alabama’s December special election for the Senate, allegations of child molestation doomed Roy S. Moore, the Republican candidate, and vaulted Doug Jones, a Democrat, into Congress.

A district in Pennsylvania that Mr. Trump carried by about 20 points flipped to the Democrats in March. Races for these seats have each had only one contested race in the last three general elections.

Change in margins of victory for seats that flipped to Democrats

Multiple forces are behind the swing: Republican voters appear demoralized while Democrats are fired up, and some voters who typically lean Republican have been shifting away from the party.

So far, Republicans have benefited greatly from being able to choose most of the spots they have been forced to compete in. Five of the eight special elections arose because Mr. Trump selected the sitting Republican lawmaker there for a position in his cabinet. (In the other three cases, Republicans resigned from Congress amid scandal or to join the private sector.)