In two years, President Trump went from despairing that his presidency would be destroyed by special counsel Robert Mueller’s probe to exulting Thursday that his exoneration signifies “game over” for his partisan tormentors.

When the president learned in May 2017 that Mr. Mueller had been appointed to investigate suspected collusion by the Trump campaign with Russia, Mr. Trump slumped in a chair and exclaimed, “I’m f—d,” according to the special counsel’s 400-page report.

“This is the end of my presidency,” Mr. Trump told close aides.

But with the release of the Mueller report showing no collusion and no obstruction of justice, Mr. Trump told a cheering audience of veterans at the White House with understatement, “I’m having a good day.”

Former Trump attorney John M. Dowd, who defended the president for about a year during the investigation, called Mr. Trump’s initial recoiling from the special counsel’s appointment “an emotional reaction.”

After that, the president fought back publicly with increasing intensity against what he called the “witch hunt.” Behind the scenes, the president and his attorneys followed a strategy of cooperating fully with Mr. Mueller’s investigation, however frustrating it was for Mr. Trump.

“He got through it because he does have a fight game in him,” said a Republican close to the White House. “That’s all the guy knows, is fight, fight, fight.”

Mr. Dowd said the president survived the investigation because he cooperated fully, by turning over millions of documents to the Mueller team and declining to assert executive privilege over any information.

“To me, all the credit goes to the president,” Mr. Dowd said. “Even not asserting executive privilege — that’s how we got the information to Mueller so quickly. We gave Bob everything.”

The investigators didn’t see it that way.

Mr. Mueller felt Mr. Trump’s written answers, including more than 30 times he said he didn’t recall something, were inadequate. The special counsel asked again late last year for an in-person interview with the president.

Mr. Trump again declined, and Mr. Mueller concluded it wasn’t worth the court battle that would ensue if he insisted on issuing a subpoena against the president for testimony.

“We determined that the substantial quantity of information we had obtained from other sources allowed us to draw relevant factual conclusions on intent and credibility,” the investigators said.

However, Mr. Dowd said he is glad that the president provided written answers to the special counsel’s questions instead of giving testimony in person. Mr. Dowd said Mr. Mueller had no legal basis for questioning the president face-to-face.

Mr. Trump agitated with his advisers to answer questions in person, but his legal team warned the president that it was a perjury trap. The attorneys eventually won out.

“You can’t say the president deprived them of any information,” he said. “I’m just glad he took our advice eventually because it was a trap. Seeking his testimony, given what the law is, was pure mischief by Bob and a way to slow-roll this for another year. It’s disgraceful.”

Mr. Dowd said he grew even more disgusted with Mr. Mueller and his team as he read through the report Thursday for waging a “partisan” investigation that resulted in a “completely unnecessary” report.

“You don’t write a 400-page report,” Mr. Dowd said in an interview. “What this report does, it tries to feed the negative narrative, which I think is wrong, I think it’s political, which a department of professionals should never do. I’m very, very disappointed with the special counsel and his people.”

Mr. Dowd said of the report, “They don’t credit [the president] like the attorney general did for the extraordinary cooperation. That is the opposite of corrupt intent. Why would a guy try to obstruct a case that he completely cooperated with, gave all his notes, all his witnesses?”

He said the exhaustive nature of the report, which didn’t recommend any charges, proves that the special counsel’s investigation was politically motivated.

“I now believe this was all partisan,” Mr. Dowd said. “They were out to get [the president]. This document is Exhibit A in any case to find out whether they were political or not. This is not a fair document at all. What I’m reading now, you could almost say The New York Times wrote this memorandum.”

One Republican close to the White House disagreed.

“Anything less would have left questions in the mind of the public,” said the person, calling the report “a very damning portrait” of the president and his inner circle.

“It’s embarrassing that the president of the United States acted like a lying bully,” the Republican said. “But that’s who they are. Their default position is to lie. They don’t do it for criminal purposes; they do it because they don’t want to be embarrassed politically. To be honest, they’re not smart enough to obstruct justice.”

The report said Mr. Trump directed his communications team three times to mislead the public over the reasons for the June 2016 Trump Tower meeting with a Russian lawyer who had promised dirt on Democratic presidential nominee Hillary Clinton. But those lies did not amount to obstruction of justice, the report said.

Mr. Mueller also said White House press secretary Sarah Huckabee Sanders acknowledged in testimony that there was no basis for her assertion to the media in 2017 that “countless” FBI agents had told the White House that they had lost confidence in fired FBI Director James B. Comey.

Mr. Dowd said the report suggests to him that Mr. Mueller was influenced too much by Mr. Comey and former Deputy FBI Director Andrew McCabe.

“It looks like Mueller bought Comey and McCabe hook, line and sinker,” he said. “Huge mistake. Those boys are in trouble. They cooked this thing up. That’s the next round, will be finding out what happened there.”

The president and his advisers are calling for an investigation into the origins of the FBI’s counterintelligence probe of the Trump campaign in 2016. Attorney General William Barr has said he is reviewing those actions but has opened no formal investigation.

“We do have to get to the bottom of these things,” the president said during an event with Wounded Warriors at the White House. “This hoax, it should never happen to another president again.”

Trump campaign manager Brad Parscale said that “now the tables have turned, and it’s time to investigate the liars who instigated this sham investigation into President Trump, motivated by political retribution and based on no evidence whatsoever.”

“Now that the collusion and obstruction conspiracy theories have been exposed for the pathetic hoaxes they always were, the Obama-era DOJ and FBI must answer for their misdeeds and the scam that they perpetrated against the American people. Justice will be served,” Mr. Parscale said.

White House counselor Kellyanne Conway, who managed Mr. Trump’s campaign, called the investigation a “political proctology exam” and said the campaign didn’t need any help from Russia to defeat Mrs. Clinton.

“When I needed to find negative information about Hillary Clinton and how to beat her, I look no further than Hillary Clinton,” she said.

Outside the White House on Thursday, tourists gathered as usual to take photographs on a fine spring day. Trump supporter Paul Belka of American Fork, Utah, who sported a “MAGA” cap, said he doubts the president ever considered giving up his battle against the special counsel’s investigation.

“He’s had a fight with the Democrats and the Republicans this whole way,” Mr. Belka said. “I didn’t elect him to be my religious leader. He’s doing a job.”

He said he believes the president didn’t try to stop the investigation despite its apparent partisan basis.

“Certainly he knows that he didn’t have any Russian collusion,” Mr. Belka said. “So he cooperated with it. But [Democrats] are not going to ever let it go. They’re continually going to try to bring him down any way they can.”

⦁ Stephen Dinan, Jeff Mordock and Bailey Vogt contributed to this report.