Wading into a tight Republican Senate primary in Pennsylvania, former President Donald J. Trump endorsed Mehmet Oz on Saturday, throwing his weight behind the former star of “The Dr. Oz Show,” who has been attacked by rivals as a closet liberal. Dr. Oz’s celebrity appears to have been a deciding factor for the former president, whose own political career was grounded in reality television.

“I have known Dr. Oz for many years, as have many others, even if only through his very successful television show,” Mr. Trump said in an announcement, upstaging a rally he was holding at the same time in North Carolina, where his endorsement of Representative Ted Budd in a tight Republican Senate race is also considered crucial.

“He has lived with us through the screen and has always been popular, respected and smart,” Mr. Trump added. He cited an appearance he had made on Dr. Oz’s daytime television show in the thick of the 2016 presidential race, when Mr. Trump showed partial results of a physical. “He even said that I was in extraordinary health,” Mr. Trump said, “which made me like him even more (although he also said I should lose a couple of pounds!).”

The former president also emphasized Dr. Oz’s electability, citing his appeal to women because of his daytime TV show. Women “are drawn to Dr. Oz for his advice and counsel,” Mr. Trump said, adding: “I have seen this many times over the years. They know him, believe in him and trust him.” Mr. Trump predicted that Dr. Oz would do “very well” in Philadelphia and Pittsburgh, which are Democratic strongholds.

A wealthy first-time candidate, Dr. Oz is in a bitter, high-priced battle with another superwealthy rival for the G.O.P. nomination, David McCormick, a former chief executive of the world’s largest hedge fund. Both candidates have ardently sought Mr. Trump’s endorsement, both personally and through surrogates, as they have awkwardly remade themselves from middle-of-the-road, establishment Republicans to appeal to Mr. Trump’s hard-right base. Dr. Oz welcomed the endorsement in a statement that said, “President Trump wisely endorsed me because I’m a conservative who will stand up to Joe Biden and the woke left.”

A poll last week by Emerson College and The Hill found a virtual tie between the two candidates among very likely primary voters, with Mr. McCormick at 18 percent, Dr. Oz at 17 percent and 33 percent undecided.

In North Carolina, Mr. Trump repeated his endorsement of Dr. Oz, likening his long television run as proof of political viability. “When you’re in television for 18 years, that’s like a poll.’‘ Mr. Trump said of Dr. Oz, whose show ended a 12-year run in January. “That means people like you.”

The Pennsylvania race, to fill the seat of the retiring Senator Pat Toomey, a Republican, is widely seen as one of the most crucial in both parties’ efforts to win control of the Senate in this year’s midterm elections. Democrats have a hard-fought primary of their own, featuring most prominently Lt. Gov. John Fetterman and Representative Conor Lamb.

After Mr. Trump’s endorsement, Mr. McCormick’s top strategist, Jeff Roe, tweeted that Mr. McCormick “is going to be the next Senator” from Pennsylvania.

Jacob Flannick contributed reporting.