WASHINGTON — Republicans narrowly averted political disaster in the West Virginia Senate primary on Tuesday with the defeat of former coal executive Don Blankenship while mainstream Democrats fended off a liberal insurgent in the Ohio governor’s race, bringing relief to the establishment of both parties on a day of elections in four states.

But Washington Republicans were handed a stinging defeat in North Carolina, where Representative Robert Pittenger was defeated by Mark Harris, a pastor who made his name denouncing same-sex marriage. The unexpected setback is likely to jolt congressional Republicans yet again and underscore that their fragile House majority is the party’s most vulnerable front in 2018.

In the West Virginia Senate primary, Mr. Blankenship came in a distant third after an 11th-hour intervention by President Trump that was coordinated by Senate Republicans. They saw Mr. Blankenship as unelectable and unworthy of the Senate, given that he served a year in prison in connection with a mining disaster in 2010 that killed 29 men, and made racially offensive comments during the campaign.

[Read our six takeaways from Tuesday night’s primary elections.]

West Virginia Attorney General Patrick Morrisey won the Republican nomination to challenge Senator Joe Manchin III, one of the most vulnerable Democrats seeking re-election this year.