Senator Orrin G. Hatch of Utah, the longest-serving Senate Republican, announced Tuesday that he would retire at the end of the year, rebuffing personal pleas from President Trump to seek an eighth term and paving the way for Mitt Romney, a critic of Mr. Trump’s, to run for the seat.

Mr. Hatch’s decision marks another political setback for Mr. Trump, who lost a Senate seat in Alabama after his preferred candidates were rejected. He also faces an exodus of Republicans from both chambers of Congress and has been warned of a political typhoon in November.

Mr. Romney’s potential ascent is particularly alarming to the White House because the former presidential candidate has an extensive political network and could use the Senate seat as a platform to again seek the nomination. Even if he were not to run again for president, a Senator Romney could prove a pivotal swing vote, impervious to the entreaties of a president he has scorned and able to rally other Trump skeptics in the chamber.

“When there are things he agrees with him on, he’ll be a big supporter,” Spencer Zwick, Mr. Romney’s longtime fund-raiser, said of Mr. Romney and Mr. Trump. “And when there are things he disagrees with, he’ll voice that.”