Republican primary voters rewarded loyalty to President Donald Trump in primary races Tuesday, ousting South Carolina Rep. Mark Sanford, a vocal critic of the president, and nominating Trump ally Corey Stewart for a U.S. Senate seat in Virginia.

Together, the two primary results were a sign of how thoroughly Mr. Trump has come to dominate the Republican Party.

In the Charleston-based district in South Carolina, Rep. Katie Arrington was declared the winner by the Associated Press. She accused Mr. Sanford of being disloyal to the president, portraying him as a Trump adversary because he had been openly critical of some of the president’s policies and provocative statements.

Mr. Trump weighed in directly in the race Tuesday afternoon—just three hours before the state’s polls closed—with an endorsement of Ms. Arrington, in a Twitter message that attacked Mr. Sanford.

“Mark Sanford has been very unhelpful to me in my campaign to [Make America Great Again],’’ he tweeted. “He is MIA and nothing but trouble.”