WASHINGTON—Alabama Republicans punished GOP Rep. Martha Roby for her disavowal of President Donald Trump during the 2016 campaign, forcing the four-term incumbent into a primary runoff to retain her seat.

Alabama was one of several states to hold primaries on Tuesday. While Ms. Roby’s weak showing showed the risk to GOP candidates who have crossed the president, Iowa Democrats chose a mainstream standard-bearer to run in a congressional district in Des Moines, rejecting a Bernie Sanders acolyte who was running there.

The...