“This race is about a governor who has brought a bad agenda to the people of Kentucky, and while he has done that, he has mocked our people, he’s called them names, he’s disrespected them, he’s locked them out of the Capitol building,” said Rocky J. Adkins, the Democratic state House leader and runner-up in the Democratic primary to Mr. Beshear. “I think after a while when you slap people around long enough and you knock down people, you kick them long enough, they’re going to find a time to get even.”

The intensely close vote in such a conservative state demonstrated the limits of attempting to nationalize state elections, highlighted the anti-Trump intensity of urban and suburban voters and heartened moderate Democrats eyeing 2020 who were delighted to see a pragmatic candidate unseat a disliked Republican incumbent.

Taken together with the Democrats’ capture of the Virginia state legislature, the Kentucky results indicate that liberal and moderate voters are as energized now as they were in last year’s midterm elections.

But just as 2018 demonstrated that Republicans can still make gains in conservative states, no matter how poor the national political environment, Tuesday also captured the limitations Democrats face in red states when they are not running against flawed opponents. In Mississippi, Democrats fielded their most promising nominee for governor in 16 years, Attorney General Jim Hood, but could not come within five points of defeating Lt. Gov. Tate Reeves, who had faced a contested primary.

These results make the last campaign of 2019, the Louisiana governor’s race a week from Saturday, even more symbolically important: It is a test of whether a relatively popular Democrat, Gov. John Bel Edwards, can be re-elected against a little-known Republican businessman, Eddie Rispone, in a pro-Trump state. The president appeared with Mr. Rispone on Wednesday in Louisiana, but it was the results Tuesday from across the state line, in Mississippi, that seemed ominous for Democrats.

Mr. Hood was well-funded, received help from national Democratic groups and hoped to defeat the button-down Mr. Reeves with a down-home style and old-fashioned populism, including a promise to expand Medicaid under the Affordable Care Act.

But Mr. Hood was unable to win over working-class white voters, including many who voted for him in his previous races for attorney general.