Evan Vucci / AP

Loyalty is something President Donald Trump demands, but doesn’t necessarily return. Just ask ex–White House Counsel Don McGahn.

In recent weeks, the president has turned on his former lawyer for making some of the most explosive claims about Trump’s conduct in Special Counsel Robert Mueller’s report. “Never a big fan!” Trump tweeted earlier in May, suggesting he had been tempted to fire McGahn. Just this week, he barred McGahn from testifying to the House Judiciary Committee about what he saw and heard inside the White House.

But McGahn’s service may have been more valuable to Trump than he realizes—it could even wind up prolonging his presidency.

Because Trump never saw McGahn as a confidant—because he didn’t look to him much for legal advice—McGahn had more time and space to pursue a pet project: stocking the courts with conservative judges, former White House aides told me. And with multiple lawsuits threatening Trump’s interests wending their way through the courts, federal judges hold enormous sway over the president’s fate.

Judges are now deciding whether Trump has violated constitutional provisions against accepting gifts from foreign countries through visits to his Washington, D.C., hotel. They will determine whether banks and accounting firms must turn over Trump’s financial records. They will rule on whether the Treasury Department must fork over Trump’s tax returns. And there’s bound to be more litigation flowing through the courts as congressional Democrats and Trump grapple over the release of additional personal, business, and official-administration records. Unfavorable decisions could be disastrous for Trump, meaning that McGahn’s work seeding the federal courts, in particular with judges sympathetic to executive power, could prove crucial to Trump’s political survival.

“Trump is pissed off. I understand that,” said a person close to McGahn, who was not authorized to speak on the record. “But it blinds him to the reality that Don was instrumental in what everyone thinks was Trump’s biggest accomplishment: judges.”

In the view of the Senate Republican leader Mitch McConnell, nothing else that’s come out of Washington in the past two years is as enduring. “I’m a huge admirer of what he did and the contribution he made to what I think is the most important thing that we’ve done,” McConnell told me.

In some measure, all this seems fortuitous. It would have been difficult to foresee early in Trump’s presidency that the courts would end up refereeing so many existential fights over Trump, making it that much more important to install judges who are leery of other branches intruding on a president’s power. It’s also never certain how a judge with lifetime tenure will rule. A president can try to appoint jurists who reflect his or her overarching ideology, but judges themselves may not feel beholden to the president at all. Indeed, Trump-appointed judges haven’t always seen things his way. Last year, a federal district-court judge nominated by Trump, Timothy Kelly, scolded the White House for yanking the CNN correspondent Jim Acosta’s press pass and ordered that it be returned. (So much for Trump’s claim that CNN is “fake news.”)

But Trump’s nearly two and a half years in office have afforded him the time and opportunity to leave a distinct imprint on the courts—and potentially shape the consequential rulings that will come down. To date, with the help of McGahn and McConnell, Trump has appointed 107 judges to the federal courts. That includes 40 of the nation’s 179 appeals-court judgeships—a higher total than any president at a comparable point in his tenure since John F. Kennedy, according to Russell Wheeler, a visiting fellow at the Brookings Institution and an expert on the judicial system.

When Trump took office in January 2017, 41 percent of active judges had been appointed by Republican presidents, and 50 percent by Democrats, Wheeler’s research shows. As of this month, the majorities had flipped: 51 percent had been appointed by Republican presidents, and 46 percent by Democrats. Even in cases where Trump replaced an outgoing Republican-appointed judge with a new one, he has been able to nudge the courts rightward. “You replace a slightly-to-the-right, middle-of-the-road judge with a firebrand, and that’s a different story,” Wheeler says.

A common thread through some of Trump’s high-profile judicial appointments is an expansive vision of executive power—a position that jibes with his interests. In the fall of 2017, for example, the Senate confirmed the Trump nominee Joan Larsen for a seat on the Sixth Circuit Court of Appeals, based in Cincinnati. Larsen wrote an op-ed for The Detroit News in 2006 in which she defended then-President George W. Bush’s use of signing statements, through which he asserted the right to bypass a legal ban on torturing detainees, among other laws.

Larsen wrote that “the president’s independent vision of what the Constitution requires is critical” and that “denying the president a constitutional voice is the real threat to our system of separated powers.” She could be moving up if another Supreme Court vacancy arises: When Trump considered nominees to replace Anthony Kennedy last year, Larsen made the short list, losing out to Brett Kavanaugh.

In Trump’s “selection of appellate judges, he is leaning toward those who have a strong view of executive power—and even an unrestrained view of executive power,” says Senator Sheldon Whitehouse, a Democrat on the Judiciary Committee, which handles judicial nominations. “And it seems likely that they will have an effect on court decisions.”

McGahn took over the president’s judicial portfolio after Trump’s inauguration, and managed it until he left the White House last fall. He had worked as a lawyer on the president’s 2016 campaign and, earlier, as a private attorney and a commissioner on the Federal Election Commission. He also has ties to the Federalist Society, a network of conservative and libertarian lawyers whose executive vice president, Leonard Leo, has served as an outside adviser to the White House, recommending candidates for judgeships. In 2017, while talking about speculation that Trump had outsourced his judicial selections to the group, McGahn noted that he’d been part of the Federalist Society since his law-school days. “So, frankly, it seems like it’s been in-sourced,” he said.

It’s not unusual for the White House counsel to run the vetting and recruitment of judicial nominees. But McGahn was able to devote an unusual amount of energy to the task, because his rapport with Trump soured over time, said the former White House aides, who spoke on the condition of anonymity to talk more freely about internal dynamics. They’d go weeks, even months, without speaking with one another. Privately, Trump would complain that he didn’t value McGahn’s advice and ask aides for names of potential replacements. McGahn’s nickname for Trump: “King Kong.”

But McGahn found a more fruitful partnership with McConnell, who wanted to capitalize on his GOP majority and give the courts a makeover. McConnell told me in an interview that they began talking even before Trump’s 2016 election victory, devising a list of potential Supreme Court nominees. A week after the election, McConnell said that he and McGahn spoke again, embarking on a nearly two-year collaboration. McGahn would develop a pipeline of candidates, including members of the Federalist Society, which McConnell called a “farm team” for administration picks. McConnell would then quickly get them confirmed.

Cases involving Trump are being heard at the district- and appeals-court levels. A Trump appointee, A. Marvin Quattlebaum Jr., is considering at least one suit—as part of a three-judge appeals-court panel based in Richmond, Virginia—that contends that Trump violated the emoluments clause through the money coming into his Washington hotel down the street from the White House.

Overall, Trump’s strategy to combat congressional oversight is to lean heavily on the courts. He is rebuffing subpoenas from Democratic-led congressional committees and refusing to make witnesses, such as McGahn, available to testify on Capitol Hill. Some of Trump’s critics have argued that any reasonable judge would repudiate his attempts to fend off lawmakers’ oversight, because his legal team’s positions are, at their root, indefensible. Just this week, U.S. District Judge Amit Mehta, a Barack Obama appointee, rejected an argument from Trump’s lawyers that Congress doesn’t have the power to subpoena Trump’s financial records. Noting the long history of congressional investigations into presidential misconduct, the judge wrote: “This court is not prepared to roll back the tide of history.”

Laurence Tribe, a constitutional-law professor at Harvard Law School, told me that Trump’s position on congressional oversight would be “rejected by anyone but the most abject puppet for the president.

“His position, essentially, is: ‘I’m an emperor. No one can investigate me—not the Justice Department, because they’re answerable to me, and not the Congress, because they have no business investigating me,’” Tribe added. Trump’s lawyers on Tuesday appealed Mehta’s ruling to the Court of Appeals for the D.C. circuit—the court where another Trump appointee, Neomi Rao, currently serves.

In the end, legal fights involving Trump could all wash up in the same place: the Supreme Court, which, due in no small part to McGahn, now has two Trump appointees. McGahn helped shepherd Neil Gorsuch’s confirmation as a Supreme Court justice in 2017. And he was a constant presence during Kavanaugh’s confirmation, accompanying the judge as he visited senators on Capitol Hill and helping to steady him amid accusations that he sexually assaulted Christine Blasey Ford when they were teenagers.

As Kavanaugh waited to testify in response to Ford’s allegations at a Senate hearing in September, McGahn ordered aides to leave the holding room and gave the judge a pep talk, urging him to show his real emotions. What followed was a scorching defense from Kavanaugh that alienated some senators, but appeared to placate Trump and dissuade him from possibly dumping the judge in favor of someone else.

With Kavanaugh replacing Anthony Kennedy, the swing vote, on the bench, the Court seems to be more Trump-friendly terrain. In past writings, Kavanaugh has shown he is protective of presidential power and prerogatives, a position that troubled Democratic senators during his confirmation proceedings. He wrote a law-review article in 2009, for example, that argued Congress should consider a law exempting sitting presidents from criminal prosecution and investigations.

“Having seen first-hand how complex and difficult that job is, I believe it vital that the president be able to focus on his never-ending tasks with as few distractions as possible,” wrote Kavanaugh, a former aide to President George W. Bush and a member of Independent Counsel Ken Starr’s team that investigated Bill Clinton in the 1990s. “The country wants the president to be ‘one of us’ who bears the same responsibilities of citizenship that all share. But I believe that the president should be excused from some of the burdens of ordinary citizenship while serving in office.”

That mind-set would suggest the president shouldn’t have to tolerate what Trump labels “presidential harassment”—and Democrats call “oversight.” And it could ultimately help rescue Trump’s presidency.

Trump tends to hang on to grudges. He personalizes disputes. It may be a while before he forgives McGahn. It may be never. But if Trump-appointed judges who want to safeguard presidential power wind up sparing Trump from turning over potentially damaging material, he may be glad he didn’t fire McGahn after all.

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