WASHINGTON — He may have had a strategy, but Rudy Giuliani hatched it almost entirely in secret.

The White House counsel had no idea. Neither did the White House chief of staff, nor the White House press secretary, nor the new White House lawyer overseeing its handling of the Russia investigation.

They watched, agog, as Giuliani, the president’s recently installed personal attorney, freestyled on live television Wednesday night about the president’s legal troubles and unveiled an explosive new fact: That Trump reimbursed his longtime personal attorney, Michael Cohen, for the $130,000 paid to adult-film actress Stormy Daniels to ensure her silence about an alleged sexual encounter with Trump.

Giuliani’s attempt to defuse a ticking time bomb exposed Trump’s failure to divulge the full story about the Daniels hush money and highlighted contradictory public statements from him and White House spokesmen. One month ago, Trump told reporters that he did not know about the payment to Daniels, whose real name is Stephanie Clifford, or where Cohen got the money to make it.

Aides and advisers to the president – who were scrambling Thursday morning to manage the fallout of Giuliani’s interview with Sean Hannity, a Trump-friendly Fox News Channel host who also has been a Cohen client – expressed a mixture of exasperation and horror. One White House official texted a reporter a string of emoji characters in response, including a tiny container of popcorn.

A second White House official, who like most others interviewed for this story spoke on the condition of anonymity to discuss a sensitive topic, said of the president, “His story is obviously not consistent anymore.”

The episode was just the latest convulsion for a White House that perpetually navigates turbulence, careening from one crisis to another, most of them of the president’s own making. It has become standard operating procedure for Trump and his aides to deceive the public with false statements and shifting accounts.

“It’s about time that our public officials started telling us the truth,” said one former Trump adviser who remains close to the White House. “There is nobody in America who didn’t think the president had the affair with the porn star. I doubt there’s anybody in America who didn’t think the president had Michael Cohen pay off the porn star.”

In this case, Giuliani said he was trying to solve one problem for Trump – by establishing that the payment to Daniels came from personal funds and was “funneled” through a law firm, arguing it therefore did not violate campaign finance laws.

Giuliani said in an interview with The Washington Post that he discussed the issue with Trump a few days ago and that they agreed that he would reveal details about the reimbursement.

“He was well aware that at some point when I saw the opportunity, I was going to get this over with,” Giuliani said.

Asked whether he might be fired for what he told Hannity, Giuliani replied, “No, no, no! I’m not going to get fired.” Laughing, he added: “But if I do, I do. It wouldn’t be the first time it ever happened. But I don’t think so, no.”

Tony Carbonetti, a longtime friend and adviser to Giuliani, said he was dining with the former New York mayor on Manhattan’s Upper East Side on Wednesday night before he went on Fox.

He warned that those lampooning Giuliani are mistaken.

“If you’ve been around Rudy, there’s always a reason for it,” he said. “If you knew a narrative was coming out, wouldn’t you want to tell the story on your terms? . . . He wanted to get ahead of it.”

Outside the government, Trump’s band of informal advisers and alumni cheered Giuliani’s move.

“I loved it,” said Jason Miller, a former Trump campaign official who also has worked for Giuliani. “They got this news out there on their terms, and they didn’t wait around for enterprising journalists to break it. This is P.R. 101 . . . The president deserves his own team defending him, and now finally he has it.”

In a trio of tweets Thursday morning, Trump attempted to do some damage control, writing in a notably restrained style that Cohen had received a monthly retainer that did not come from the campaign and insisted that no campaign finance laws had been violated.

Aides speculated that the tweets may have been drafted by members of the president’s legal team, noting that they did not seem to be written in Trump’s singular Twitter voice.

The Cohen payment disclosure was not the only problematic comment from Giuliani in his wide-ranging interview with Hannity. He offered a reason for Trump firing former FBI director James B. Comey – because he would not publicly state that Trump was not under FBI investigation – that differed from the one provided by the administration at the time of Comey’s firing last May.

In addition, Giuliani said scrutiny from special counsel Robert Mueller toward Ivanka Trump, the president’s daughter, was inappropriate because she is “a fine lady.” But Giuliani said it would be acceptable for Mueller to scrutinize her husband, Jared Kushner, because Kushner was “disposable,” as he jokingly put it. Both Ivanka Trump and Kushner are senior White House advisers.

If Trump was upset with his lawyer’s performance, he did not show it. Indeed, the president was party to hatching the strategy, according to three people involved in the discussions.

Once on board, Giuliani spent days reading and being briefed about the many issues facing Trump, including the Cohen case and the payments made by Cohen to Daniels. Giuliani and Trump decided that it would be best to try to explain why Trump and Cohen acted as they did and clarify their business relationship, the people said.

“Giuliani is going to be dealing with all the existential threats to the Trump presidency,” said Douglas Brinkley, a presidential historian at Rice University. “If he gets Trump out of this jam, he becomes the indispensable man.”

Giuliani viewed potential federal scrutiny of election law as an issue that Trump had to address head-on rather than dodge because he believed that it could fester, according to one person who spoke with him last month. This person added that Trump was prone to trust Giuliani’s position because they had bonded privately over their shared frustrations with the Justice Department, and both wanted to run a more combative, freewheeling media campaign.

“Giuliani’s value to Trump is not just that he’s got gravitas in the room with Mueller,” said Kirtzman, author of “Rudy Giuliani: Emperor of the City.” “It’s not just that he is a television celebrity. He’s a confidant. Trump needs a confidant more than ever. He hasn’t been able to find a confidant among the lawyers he hired. The question is whether Giuliani winds him up or calms him down.”

Asked about White House officials being caught off guard by his disclosure, Giuliani told CNN on Thursday: “They were. There was no way they wouldn’t be. The president is my client. I don’t talk to them.”

David Axelrod, a senior White House adviser under former President Barack Obama, said, “It is beyond bizarre to think that one set of lawyers who are poised to defend him should hear from another of his lawyers on TV plainly material facts about his case and his own conduct. This is the reason so many lawyers apparently refused the assignment.”

Surrounded by reporters Thursday morning outside the West Wing, press secretary Sarah Huckabee Sanders declined to comment beyond what Giuliani and Trump had said earlier, citing “ongoing litigation.” At the daily press briefing, Sanders referred questions to Giuliani.

“I haven’t had that conversation with the president,” Sanders said. “I’d refer you back to the president’s outside counsel.”

Only subscribers are eligible to post comments. Please subscribe or to participate in the conversation. Here’s why.

Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.