Republican voters lashed out against traditional party leaders Tuesday, ousting Representative Mark Sanford of South Carolina and nominating a conservative firebrand for Senate in Virginia, the latest illustration that fealty to President Trump and his hard-line politics is paramount on the right.

Mr. Sanford, a former governor once seen as a possible candidate for president, lost to Katie Arrington, a state lawmaker, in a closely contested primary, The Associated Press reported. Ms. Arrington had made the incumbent’s frequent criticism of Mr. Trump the centerpiece of her campaign. And the president endorsed her in an unexpected, and deeply personal, broadside against Mr. Sanford just three hours before the polls closed.

In Virginia, Republicans dismissed the concerns of mainstream party leaders to nominate Corey Stewart, a local official who has made his name attacking illegal immigrants and embracing emblems of the Confederacy, The A.P. reported. He will challenge Senator Tim Kaine, the former Democratic vice-presidential candidate.

[Read more about Corey Stewart, Republicans and the fringe right.]

Party leaders fear that Mr. Stewart, a fervent Trump supporter who has mimicked his slashing style, could drag down other Republicans in a state that is key to control of the House.