WASHINGTON (AP) — First they cooperated. Then they stonewalled. Their television interviews were scattershot and ridiculed, their client mercurial and unreliable.

But President Donald Trump’s legal team, through a combination of bluster, legal precedent and shifting tactics, managed to protect their client from a potentially perilous in-person interview during special counsel Robert Mueller’s Russia investigation. His lawyers are taking a victory lap after a redacted version of Mueller’s findings revealed politically damaging conduct by the president but drew no conclusions of criminal behavior.

“Our strategy came to be that when we weren’t talking, we were losing,” Rudy Giuliani, one of Trump’s lawyers, told The Associated Press in a recent interview. Given that Mueller could not indict a sitting president, Giuliani said, the team kept its focus on Mueller’s “capacity to report, so we had to play in the media as well as legally.”

The aftershocks from the Mueller report released Thursday will help shape the next two years of Trump’s administration. But while the report may cause some Democrats to take a renewed look at impeachment despite long odds of success in Congress, the legal threat to Trump that seemed so dangerous upon Mueller’s appointment in May 2017 has waned.

At the outset, that appointment led Trump to predict “the end of my presidency.” The White House struggled to recruit top Washington attorneys, many of whom were reluctant to work for a temperamental, scandal-prone president who repeatedly claimed he would be his own best legal mind.

The initial strategy of the Trump legal team, including White House attorney Ty Cobb and personal defense lawyer John Dowd, was to be as cooperative as possible with Mueller’s prosecutors and ensure that investigators got access to the documents they requested and the witnesses they wanted to interview. The Trump lawyers hoped to bring about a quick conclusion to the investigation.

Believing he could exonerate himself, Trump initially expressed a willingness to sit for an interview with Mueller’s team. A date was set for that to take place at Camp David. But then the president’s lawyers moved away from the plan, in part by arguing that the special counsel already had gotten answers to his questions.

“It became the most transparent investigation in history,” Jay Sekulow, one of the president’s personal lawyers, said in an interview.

Still, there was internal tumult along the way, including the March 2018 departure of Dowd, a veteran and experienced criminal defense attorney, and the additions of Giuliani and the husband-wife team of Martin and Jane Raskin.

Even as the legal team professed cooperation with Mueller’s prosecutors, the lawyers expressed impatience, frustration and skepticism in a series of private letters that challenged the credibility of the government’s witnesses and the demands to interview the president.

In a November 2018 correspondence, one of a series of letters obtained by news outlets, the president’s legal team attacked the questions Mueller wanted to ask the president as “burdensome if submitted to a routine witness, let alone presented to the president of the United States, more than two years after the events at issue while he continued to navigate numerous, serious matters of state, national security and domestic emergency.”

Those private complaints were dwarfed by louder public protests. Trump spent months engaging in daily, sometimes hourly, attacks on Mueller’s team, declaring the investigation a “Witch Hunt” and questioning the integrity of the investigators.

Giuliani, in many ways more of a television spokesman than conventional lawyer, amplified those attacks. He went so far as to accuse the investigators of misconduct and to portray Mueller, who as a Marine officer had led a rifle platoon in Vietnam, as unpatriotic.

The former New York City mayor became a human smoke screen, making accusations and offering theories often meant to distract and obfuscate. He was a punch line on cable news channels, and his interviews were mocked as blunder-filled performances.

But there was a method to Giuliani’s shtick, at least at times. More than once he let slip revelations that initially were perceived as gaffes but later were recognized as efforts to get out ahead of potentially damaging news stories. Two examples include payments to Stormy Daniels, a porn actress who claimed an affair with Trump, and a letter of intent to build a Trump Tower Moscow.

There were missteps, too.

The interviews granted by White House staffers filled the pages of the Mueller report with stories of West Wing chaos. At least one interaction caught Mueller’s attention as a possible effort to discourage a witness from cooperating against the president.

Trump’s lawyers communicated regularly with attorneys for other people under scrutiny in the investigation as part of a joint-defense agreement that enabled them to swap information. But the report reveals that after former national security adviser Michael Flynn withdrew from the agreement and began cooperating with the government, an unidentified Trump lawyer left a message with Flynn’s attorneys reminding them that the president still had warm feelings for Flynn and asking for a “heads-up” if Flynn knew damaging information about the president.

While Giuliani, with an eye toward the members of Congress who might eventually decide the president’s fate, focused on the public relations battle, the legal team also worked behind the scenes to argue that Mueller could not use a subpoena to compel Trump to give an in-person interview, which carried potentially grave risks for a president prone to making false statements.

“I think they were right to think that it would hurt him to speak to Mueller’s team, and as it turns out, they were right to think that he could get away with refusing to speak with Mueller’s team,” said Stanford law school professor David Alan Sklansky.

Mueller’s team, which spent about a year negotiating with Trump’s lawyers over a potential interview, ultimately agreed to accept written answers on Russia-related questions but never spoke with the president in person.

Making the move to block an interview was “defense lawyering 101” because defense lawyers as a matter of course don’t like to let clients in legal jeopardy speak to investigators, said Duke law professor Samuel Buell.

Mueller never acted to subpoena Trump. The special counsel did not conclude that Trump’s campaign colluded with Russians. With an eye on following a Justice Department legal opinion that prohibits indicting a sitting president, Mueller did not rule on whether Trump obstructed justice. Attorney General William Barr and Deputy Attorney General Rod Rosenstein declared that Trump did not.

“We’re very, very happy. I mean, it’s a clear victory. I think any lawyer would say when you get a declination, you just won,” Giuliani told Fox News after the report came out.

Buell said it is hard to know how much credit belonged to Trump’s lawyers.

“I think that’s where the real lawyering in a situation like this goes on, is the client management piece,” he said. “Trump doesn’t like to be managed, clearly ... but the Mueller report won’t tell you what went on with the president’s private lawyers and the president.”

___

Lemire reported from New York. Associated Press writer Jill Colvin contributed to this report.