“I like the direction that our country is going in right now,” said Julie Hickert, 53, after casting a ballot Tuesday morning in Chesterfield, a St. Louis suburb. “He is going to continue fighting the fight.”

For Ms. McCaskill, 65, who swept into office amid Democrats’ last wave, in 2006, and was re-elected after a stroke of luck sank her opponent’s campaign in 2012, the undertow of conservative strength here proved too much this time around. Republicans made her one of their top national targets, and hammered away in personal and sometimes visceral terms.

Ms. McCaskill raised huge sums of money, rallied women in the state’s suburbs and cities, and worked furiously to preserve enough rural support to eke out a win. But it was not enough in Missouri, where Republicans have exploited deep divisions over cultural issues like abortion and race relations to execute a rapid statewide takeover.

Widely regarded as a shrewd campaigner, Ms. McCaskill turned heads in the campaign’s closing days by backing Mr. Trump’s polarizing approach to a caravan of asylum seekers marching toward the Southern border and releasing a radio ad that described her as “not one of those crazy Democrats.” She later elaborated on Fox News.

The ad and backlash against it among liberal and black voters in St. Louis and Kansas City perfectly encapsulated Ms. McCaskill’s challenge in a state that has substantial liberal, urban populations as well as rural and exurban swing voters who have moved toward the Republicans.

In the end, Ms. McCaskill suffered steep losses across the state’s rural interior.

The loss likely marks the end of life in public office for Ms. McCaskill, a singular figure in Missouri politics who began her public career more than three decades ago in a male-dominated State Capitol and outlasted most of her Democratic peers. She has long coveted the state’s governorship, having narrowly lost a bid in 2004, but on Tuesday night, she signaled that she had run her final race, though she said she would be unencumbered in speaking her mind.

“Believe it or not, I’ve really had to be kind of careful,” she told supporters here. “Not anymore. I will be out there fighting with you. I am not going away.”

The results were equally stinging for Democrats here and in Washington. As Ms. McCaskill warned Democratic voters at events across the state in the race’s final days, it may well be a long time before Democrats can compete successfully on a statewide level here again. Senate Democrats will lose an influential voice of Midwestern moderation at a time when the party is still wrestling with how best to counter Mr. Trump’s electoral success in 2020. The loss of Ms. McCaskill and other moderate Democrats, like Heidi Heitkamp in North Dakota and Joe Donnelly of Indiana, is all but certain shift Senate Democrats center considerably leftward in the next two years.