Alex Wroblewski / Reuters

When Don McGahn leaves the White House this fall, it will end one of the longest, and most improbably successful, stints in the Trump administration.

President Donald Trump announced on Twitter Wednesday morning that his White House counsel would leave after the presumed confirmation of Brett Kavanaugh to the U.S. Supreme Court. Axios had reported the news earlier Wednesday morning.

McGahn’s exit is not a great surprise—expectations of a departure sometime this fall had circulated for some time, with Kavanaugh’s appointment as the likely bookend. The greater surprise is that McGahn lasted so long in the role, and that he was so effective. He was always a somewhat unorthodox choice; he had an up-and-down relationship with the president, and he has had to withstand one of the most trying periods for any White House counsel in memory. Yet he has lasted longer in his job than almost any other top Trump White House official, and has achieved more in it than any of them, too.

McGahn came to the White House from the Trump campaign, for which he’d served as a top lawyer. Although he had some tenuous ties to the president—his uncle had represented Trump in Atlantic City—he was a strange pick. A former member of the Federal Election Commission, McGahn was a member of the Republican establishment that Trump detests. He is stylistically different from Trump. He wears his hair long (by Washington standards), plays in a rock band, and attended a lower-tier law school, which reportedly bothered the status-obsessed president. McGahn had a different key credential: He would take the job, unlike many Republicans who steered clear of the new administration.

In the White House, McGahn’s greatest accomplishment has been to oversee a remarkable overhaul of the federal courts, managing to shepherd through an unprecedented number of judges to lifetime appointments. The president now has 60 appointees on the bench. That includes 12 circuit-court judges confirmed in 2017, the most of any president in his first year. Trump has also appointed district-court nominees at a prodigious rate, and a deal in the Senate on Tuesday cleared the way for seven more. The greatest prize among the appointments is Supreme Court Justice Neil Gorsuch, and Kavanaugh is likely to join him soon. Barack Obama managed to get two justices confirmed in his entire eight years in office, in part due to Senate GOP obstruction.

Trump shows little direct interest in conservative jurisprudence, except as it affects him directly or is useful as a political tool. As a result, McGahn had broad leeway to handle the judgeships as he wanted, as Jason Zengerle recently reported in The New York Times Magazine:

As White House counsel, McGahn has exercised an unprecedented degree of control over judicial appointments. In previous White Houses, both Republican and Democrat, judicial nominations were typically crowdsourced among officials from different parts of the administration … Under Trump, the job belongs exclusively to the White House Counsel’s Office, with McGahn and his deputy, Robert Luther, and about 10 associate counsels identifying and then scrutinizing candidates. This process is unique in White House history.

McGahn worked hand in glove with the conservative Federalist Society, producing one of the Trump administration’s most successful initiatives, despite a few hiccups.

Meanwhile, a procession of advisers who had been closer to Trump or enjoyed a longer association with him came and went: the strategist Steve Bannon; Chief of Staff Reince Priebus; National-Security Adviser Michael Flynn and his successor, H. R. McMaster; Press Secretary Sean Spicer; and Communications Directors Mike Dubke, Anthony Scaramucci, and Hope Hicks. Trump’s own legal team has also been highly volatile. Yet McGahn has remained.

That hasn’t been for a lack of action or points of tension with Trump. In the first week of the administration, McGahn received a visit from Acting Attorney General Sally Yates, who warned him that Flynn was a blackmail risk by Russia. Yates was soon fired. In February, so was Flynn. (He has since pleaded guilty to lying to federal agents about his contacts with Russians.) Trump has issued several controversial, politically charged pardons, circumventing Justice Department procedures. In May, Trump fired FBI Director James Comey, angry at the investigation into Russian interference in the 2016 election. Several days later, Deputy Attorney General Rod Rosenstein appointed Robert Mueller to oversee the Russia probe as a special counsel.

That’s provided enough legal drama to fill up several seasons of prime-time TV. Trump has raged at Mueller and done several things that could be construed as obstruction of justice, including quizzing witnesses about what they told Mueller and publicly calling for the special counsel’s firing. A New York Times reporter overheard two of Trump’s outside lawyers complaining about McGahn loudly at a Washington restaurant. On at least two occasions, in June and December 2017, the president tried to fire Mueller. McGahn reportedly blocked the June attempt only by threatening to quit. He has also reportedly worked to persuade Trump not to pardon Paul Manafort, his former campaign chair who was convicted on eight felony counts this month and faces many more in a separate trial in September.

McGahn’s refusal to fire Mueller last summer may well have saved Trump’s presidency—as Richard Nixon’s Saturday Night Massacre shows, such a ham-fisted cover-up often does great damage to a president. Yet the fact that Trump continues to lambaste Mueller shows how thin a barrier McGahn was to the president getting his way. McGahn’s successor has not yet been named, though Emmet Flood is presumed to be a strong candidate. Whether he will be as effective at corralling the president’s emotions is yet to be seen.

Earlier this month, Trump’s personal legal team was stunned by news of how deeply McGahn had been cooperating with Mueller’s team. After the president declined to assert executive privilege and try to prevent Mueller from interviewing the White House counsel, McGahn spoke for at least 30 hours to the special counsel’s team. Trump’s personal lawyers reportedly had little grasp of what he had said, though McGahn’s own attorney said he had not implicated the president in any crimes.

Trump contrasted McGahn with John Dean, the Nixon White House counsel who eventually testified against the president:

Yet Trump has also reportedly questioned McGahn’s loyalty. There’s nothing to suggest a Dean-like flip on McGahn’s part, but the president isn’t totally off base. McGahn has construed his role as defending not the president per se but the presidency itself. That has led him to be frustrated by some of Trump’s moves, and to push for more aggressive assertions of executive privilege in order to protect the prerogatives of future White Houses. The outcome of the Mueller investigation and other legal inquiries into Trump will eventually show how effectively the White House counsel was able to protect both the president and the presidency. By then, Don McGahn will be long gone.

We want to hear what you think about this article. Submit a letter to the editor or write to letters@theatlantic.com.