WASHINGTON—President Donald Trump hatched with Rudy Giuliani the high-risk plan to disclose on live television that he had reimbursed his longtime attorney for buying a porn actress’s silence, leaving senior aides in the White House and the rest of his legal team stunned.

Mr. Giuliani, the former New York City mayor and recent addition to the president’s legal team for the Russia investigation, said Wednesday on Fox News that the president had reimbursed his lawyer, Michael Cohen, for the October 2016 payment of $130,000 to Stephanie Clifford, professionally known as Stormy Daniels, in exchange for her signing a nondisclosure agreement about an alleged sexual encounter with Mr. Trump in 2006.

White House press secretary Sarah Sanders, who has for months told reporters that Mr. Trump had no knowledge of the payment, said Thursday that the first time she learned the president had reimbursed Mr. Cohen was from Mr. Giuliani’s interview Wednesday.

Several White House aides were alarmed by Mr. Giuliani’s move and concerned that he is operating outside the White House staff structure, taking cues from the president and using the television platform he commands as a celebrity in his own right.

“People in the White House are a little concerned about what looks like the roller coaster ride ahead,” one White House official said.