Donald Trump has lamented that no one on the White House legal team is his kind of lawyer: a bulldog who will protect him. Over the past two years, he’s said he wanted lawyers who will safeguard his interests the way he believes John F. Kennedy’s brother Robert did as attorney general. “Where’s my Roy Cohn?” he reportedly asked once, referencing the notorious lawyer he worked with earlier in his career.

Don McGahn is nothing like Cohn. As White House counsel, he regularly frustrated Trump by pushing back on his ideas, in some cases flatly refusing to carry out orders, according to the report from Special Counsel Robert Mueller. But as much as they displeased the president, McGahn’s efforts may have saved Trump from his worst enemy: himself.

Mueller’s report details how McGahn kept Trump from making potentially catastrophic decisions on how to respond to the investigation. McGahn defended Attorney General Jeff Sessions’ recusal from the probe, stage-managed the firing of FBI Director James Comey, declined to order Deputy Attorney General Rod Rosenstein to fire Mueller — twice — and refused to lie to reporters about the firing attempts. Trump has not emerged unscathed from the Mueller investigation, but the fact that he has so far avoided some of the worst-case scenarios is in large part a testament to McGahn.

McGahn’s decisions during the Mueller probe are just one reason why he is likely to be viewed in hindsight as one of the pivotal players of Trump’s first term. The former White House counsel, who left the administration last fall, also successfully shepherded two conservative judges onto the Supreme Court as well as scores of lower court judges, helping to reshape the direction of the nation’s judiciary. And he was one of the primary architects of the administration’s push to slash a wide range of federal regulations.

The fact that McGahn’s recollections are in the Mueller report in such great detail is remarkable on its own. It is unusual for a lawyer to share so openly with investigators probing his client. (The New York Times reported in 2018 that McGahn was interviewed by Mueller’s team for more than 30 hours.) And the White House chose not to try to redact any of his testimony by asserting executive privilege. His interviews reveal numerous high-stakes battles with the President behind the scenes.

On March 3, 2017, Trump called McGahn into the Oval Office after Sessions had recused himself from overseeing the Russia investigation. The President blamed McGahn, and he “wanted McGahn to talk to Sessions about the recusal,” according to the report. But the lawyer resisted, arguing that the Justice Department found the recusal was proper. “McGahn told the President that DOJ ethics officials had weighed in on Sessions’s decision to recuse,” the report says. Trump was so angry that he “screamed at McGahn,” according to former White House strategist Steve Bannon, who was present at the meeting.

That wasn’t the only time McGahn was chewed out by his boss for offering sound advice. Just one month later, on April 11, 2017, Trump admitted to McGahn that he had twice asked the FBI director to publicly announce that Trump wasn’t under investigation. “The President acknowledged that McGahn would not approve of the outreach to Comey,” the report states, “because McGahn had previously cautioned the President that he should not talk to Comey directly to prevent any perception that the White House was interfering with investigations.”

After Trump fired Comey and Mueller was appointed special counsel, the fights between the President and his lawyer grew more intense. Trump was angered when Justice Department ethics officials officially cleared Mueller to serve as special counsel on May 23, and he told McGahn to call Rosenstein, who was in charge of overseeing the investigation. “McGahn told the President that he would not call Rosenstein and that he would suggest that the President not make such a call either,” the report said, citing contemporaneous notes taken by one of McGahn’s aides. McGahn advised that the President could discuss the issue with his personal attorney but it would look like he was trying to meddle in the investigation and could be used against him in an obstruction-of-justice case.

The most consequential clash between Trump and McGahn came soon after, on June 17. Trump, who was at Camp David, called McGahn at home and ordered him to have Mueller fired. According to McGahn’s interviews with Mueller’s team, Trump called him twice, both times insisting he call Rosenstein and tell him that Mueller had conflicts preventing him from serving as special counsel.

“McGahn was perturbed by the call and did not intend to act on the request,” the report states of McGahn’s feelings after the first call. The lawyer was worried the President’s request could tip off a “Saturday Night Massacre” situation at the Department of Justice, akin to the famous series of resignations under President Richard Nixon. Feeling “trapped,” McGahn told his lawyer, White House chief of staff Reince Priebus and Bannon that he was resigning, according to the report. He even packed up his office. But Trump never asked him if he had followed through on the call to Rosenstein, and McGahn wound up staying on for more than a year.

On January 25, 2018, the New York Times broke the story that Trump had ordered McGahn to have Mueller fired, and that McGahn threatened to quit instead. The following day, Trump pressured McGahn to put out a statement denying the story, according to the report, but McGahn refused. Days later, another White House staffer told McGahn that Trump might fire him if he didn’t refute the Times story, but “McGahn dismissed the threat, saying that the optics would be terrible if the President followed through with firing him on that basis,” the report says. The following day, Trump met with McGahn in the Oval Office and asked him to issue a correction. “McGahn thought the President was testing his mettle,” according to the report, and never publicly denied the story.

McGahn left his post in October with relatively little fanfare, shortly after Justice Brett Kavanaugh’s controversial Supreme Court confirmation. Though Trump butted heads with his counsel, the Mueller report makes clear how critical McGahn’s judgment proved to be. “The President’s efforts to influence the investigation were mostly unsuccessful,” the report states, “but that is largely because the persons who surrounded the President declined to carry out orders or accede to his requests.”

Write to Tessa Berenson at tessa.berenson@time.com.