This week, we saw President Donald Trump accept the resignation of Environmental Protection Agency Administrator Scott Pruitt, whose extraordinary record of malfeasance in office finally appeared to do more harm than good for the president.

The last straw for Trump, according to the New York Times, was the CNN report that Pruitt suggested that Trump fire Attorney General Jeff Sessions so that Pruitt could run the Justice Department:

The idea had been discussed privately for months by the president, who occasionally asked advisers if it was a good idea, according to two people familiar with the discussions. But seeing those deliberations being aired publicly, amid a string of other damaging reports, focused Mr. Trump’s attention, a person close to the president said.

In an administration run by a president who made “you’re fired” his catchphrase, and who has unceremoniously relieved other subordinates, the scandal-plagued EPA administrator seemed to have figured out the secret to longevity. But ultimately, it was Pruitt’s own career ambitions that undermined him.

The list of Pruitt’s indiscretions quickly grew long, comical, and (eventually) embarrassing for the White House: He built a $43,000 phone booth. He had an aide scout a used Trump hotel mattress. He sent security officials to find lotion used in Ritz-Carlton Hotels. He ate too often at the White House.

Then there were the more serious potential ethical and legal violations, like getting a sweetheart condo deal from a lobbyist, deleting calendar records and firing a staffer for objecting, and using his post to try to get his wife a $200,0000-a-year job.

That he persisted for so long showed just how far his tribe was willing to go to excuse or dismiss his indiscretions as he fashioned the EPA to suit the needs of fossil fuels, chemical manufacturers, and automakers. Pruitt remained in good standing even on Wednesday, attending a Fourth of July party at the White House with other Cabinet officials.

EPA Administrator Scott Pruitt at WH Fourth of July picnic. pic.twitter.com/7t9hPAZ72D — darlene superville (@dsupervilleap) July 5, 2018

Yet on Thursday, President Trump finally asked for Pruitt’s resignation and Bloomberg reported that the administrator was “devastated.” Here are some of the factors that kept him in place for so long.

Pruitt was late to board the Trump train, but he rode it until the bitter end

In 2016 interview, Pruitt told a Tulsa radio station that “Donald Trump in the White House would be more abusive to the Constitution than Barack Obama.”

But Pruitt pulled a hard 180 on Trump and became one of the president’s most obsequious defenders. Unlike former Secretary of State Rex Tillerson, who called Trump a “fucking moron,” Pruitt never had anything bad to say about the president after taking office. Pruitt called Trump “courageous” for announcing that the United States is planning to withdraw from the Paris climate accord, for example.

He quickly became a close personal ally of the president. “The two speak frequently, and the president enjoys discussing his negative view of Jeff Sessions, the attorney general, with the embattled E.P.A. leader,” according to the New York Times.

Pruitt fed Trump’s ravenous ego, became a confidant, and swung back at critics. He also played up his conservative principles and emphasized his evangelical faith, which helped insulate him from the mounting controversy.

Even his resignation letter was filled with cloying sycophancy:

My desire in service to you has always been to bless you as you make important decisions for the American people. I believe you are serving as President today because of God’s providence. I believe that same providence brought me into your service. I pray as I have served you that I have blessed you and enabled you to effectively lead the American people. Thank you again Mr. President for the honor of serving you and I wish you Godspeed in all that you put your hand to.

Trump was also quite fond of Pruitt, at least rhetorically. “Scott is a terrific guy,” Trump told reporters this week aboard Air Force One. “He came to me and said I have such great confidence in the administration I don’t want to be a distraction. ... He’ll go and do great things and have a wonderful life, I hope.”

When confronted with allegations of impropriety, Pruitt deployed Trump’s playbook: deny wrongdoing, blame underlings, and attack the media.

Pruitt delivered for Trump like few others in the Cabinet

There’s been a robust back-and-forth about whether Pruitt was actually effective in implementing his agenda at the EPA. Dismantling environmental rules is an arduous, tedious process. Some of Pruitt’s proposals are bogged down in litigation and others were thwarted because officials didn’t follow proper procedures.

Pruitt has managed to delay some regulations, but many of his announcements of new policy changes were just that: announcements. The US can’t withdraw from the Paris agreement until 2020, for example. The EPA is only starting the process of rolling back vehicle emissions rules. And if Pruitt wants to undo the Obama-era Clean Water Rule, he has to come up with an alternative that can withstand a lawsuit. Same deal for the Clean Power Plan.

A hostile Congress after November’s election could slow this progress and another administration in 2020 could reverse much of it.

But that’s besides the point. Pruitt, and more importantly, Trump, treated these announcements and delays like wins. So did members of Congress.

“We are always interested in ways we can stop federal overreach and that is something that is so important to my constituents in Tennessee,” said Rep. Marsha Blackburn (R-TN) to Pruitt during one his hearings last April. “They’re very grateful that we had the delay in the [Waters of the United States] rule.”

Even with control over all three branches of government, the Trump administration has struggled to advance its agenda. It failed to repeal Obamacare, for example. So regulatory rollbacks, even announcements thereof, are precious points on the board. There are at least 45 environment-related regulations (the New York Times tallied 76) being repealed or whittled down since Trump took office, with at least 25 at the EPA.

Pruitt’s religion and conservatism forged a bridge to Trump’s base

Trump’s religiosity and conservative credentials were always suspect, in belief and in action. And Pruitt served as a valuable salve to voters who care about that sort of thing.

Vox’s Tara Isabella Burton goes into some depth about how Pruitt used to his faith to guide his policy agenda, but noted that Pruitt’s evangelical beliefs helped shield him as well:

Pruitt’s evangelical bona fides and ability to engage with the evangelical leaders who are, increasingly, shoring up Trump’s base may have better allowed him to weather some of his early scandals and last as long as he has.

During his tenure, he attended a Bible study with other Cabinet officials, including Attorney General Jeff Sessions, Housing and Urban Development Secretary Ben Carson, and Energy Secretary Rick Perry. Responding to allegations that he misused his office to help his wife open Chick-fil-A restaurant, Pruitt said he was interested because Chick-fil-A is “a franchise of faith.”

Small government conservatives also found an ally in Pruitt, reported the New Yorker’s Margaret Talbot:

Lots of conservative think-tank types love Pruitt, too, for giving industry a break; for energetically pursuing an anti-regulatory, federalist agenda; and for not being especially worried about global warming.

Pruitt’s work at the EPA has pleased major Trump donors, like coal baron Robert Murray. Conservative media outlets also slavishly defended Pruitt. In fact, firing Pruitt may hurt Trump in some circles.

“The president should have protected him better,” Doug Deason, a Dallas donor and prominent Trump supporter who fund-raises for the pro-Trump America First PAC told the Washington Post. “I’m extremely disappointed. He’s the only Cabinet secretary who has done what he was told to do. This is one of the only big blunders of his administration.”

Pruitt’s downfall was turning on one of Trump’s own

The mountain of corruption allegations didn’t move the needle at the White House, but internecine personal drama did (Pruitt and Sessions’s next Bible study might be a bit awkward). This puts Pruitt in line with Tillerson, former Health and Human Services Secretary Tom Price, and former Veterans Affairs Secretary David Shulkin. These officials all had their own ethics troubles, but alienating Trump was the main reason they got fired.

Conservative media, including outlets that once praised Pruitt, also started to turn against him.

Pruitt is the swamp. Drain it. — Laura Ingraham (@IngrahamAngle) July 3, 2018

Pruitt’s Deputy Administrator Andrew Wheeler, who was previously a coal lobbyist, an EPA official, and a staffer for Sen. James Inhofe (R-OK), is taking over the EPA and will likely keep a lower profile than Pruitt. But with a looming election in November, Trump may miss having a fighter in his corner who can run up the score.