If you’ve read the conflicting accounts of Navy Secretary Richard V. Spencer’s sudden departure from the Trump administration, you’d probably think it was solely about a dispute over the fate of a Navy SEAL. But that ignores the long history that led up to Spencer’s dismissal Sunday. He had long lost the confidence of President Trump and many other top administration officials and had been on shaky ground for months. The fight over SEAL Eddie Gallagher was merely the straw that broke the camel’s back.

Spencer had, over time, run afoul of several Trump-world factions. Several officials told me his position had been untenable ever since the departure of Defense Secretary Jim Mattis, who brought Spencer into the administration. Mattis and Spencer served together on the board of the Center for a New American Security.

Spencer is now attempting to “pull a Mattis,” one senior administration official said, by seizing upon an issue that paints him in a just light, to try to exit the Trump administration honorably. “He’s trying to make himself a martyr,” the official said, adding that Trump had been repeatedly dissatisfied with Spencer.

On Saturday at the Halifax International Security Forum, Spencer repeatedly denied reports he was planning to resign over the Gallagher issue. He also said he would not follow Trump’s order-by-tweet to circumvent the regular process and let Gallagher keep his SEAL status and his Trident pin.

Spencer didn’t know that on Friday, a senior White House official had told Defense Secretary Mark T. Esper and Gen. Mark A. Milley, the chairman of the Joint Chiefs of Staff, about Spencer’s efforts to secretly negotiate a compromise that would end with Gallagher keeping his status. That undermined Esper’s attempts to persuade Trump to change course.

On Sunday evening, Esper announced he had asked for the Navy secretary’s resignation. He said Spencer had circumvented the chain of command by going behind Esper’s back. Esper said Monday he fired Spencer for insubordination.

“Secretary Spencer broke these rules, and thus lost my trust and confidence,” Esper said in a news conference Monday morning. “Contrary to the narrative that some want to put forward in the media, this dismissal is not about Eddie Gallagher. It’s about Secretary Spencer and the chain of command.”

We know there was even more going on because Trump tweeted as much, just minutes after Esper had laid out his story. Trump mentioned that “contracting procedures were not addressed to my satisfaction.” Officials told me that Trump was referring to Spencer’s failed promise to fix the elevators and other cost overruns on the USS Gerald R. Ford aircraft carrier, a pet peeve of the president.

Defense officials insist it was Esper’s call to get rid of Spencer. That may be true, as far as it goes, but it ignores the larger context. Spencer was not considered to be on the Trump team. He was seen as Mattis’s guy, and Trump remains bitter about Mattis. In the Trump administration, it’s all about factions. Those factions change over time and form assorted alliances based on overlapping interests. Spencer had lost his.

Spencer also ran afoul of Treasury Secretary Steven Mnuchin, officials said, by coming out publicly on an issue that Mnuchin felt strongly about. In August, Spencer penned an op-ed in the Wall Street Journal calling for the Federal Retirement Thrift Investment Board to reverse its plan to direct billions of dollars of U.S. service members’ retirement funds in companies that are owned by China and Russia. Mnuchin opposes the change because of concern over its impact on Wall Street and was upset Spencer had gone public.

In the end, Spencer was left without allies. The president’s attitude toward him was well known inside the White House. It’s a familiar pattern: Once Trump starts talking to staff about an official’s dismissal, it’s just a matter of time.

In his resignation letter Sunday, which appears to have be well thought out despite Spencer’s claim that he wasn’t contemplating resigning, Spencer claimed the high moral ground and took a direct shot at Trump over the Gallagher case.

“Unfortunately it has become apparent that … I no longer share the same understanding with the Commander in Chief who appointed me, in regards to the key principle of good order and discipline,” he wrote, adding that the president deserves someone “aligned with his vision.”

That’s exactly the tack Mattis took in his resignation letter, after Mattis resigned purportedly over Trump’s decision to suddenly withdraw all U.S. troops from Syria. Trump later reversed that decision, then announced it again and then reversed it again. Like Spencer, Mattis’s relationship with Trump had soured long before that. Like Spencer, Mattis wanted an exit on his own terms with the sympathy of Congress and the media.

Spencer doesn’t deny that he was working secretly with the White House on a plan to ultimately game the process, which undermines his argument that he was defending the process. And by not looping in his immediate boss, Esper, he burned his last bridge.

None of this history changes the fact that the president of the United States intervened in a case of military justice in a way that both his defense secretary and Navy secretary were opposed to. But this context is crucial for understanding what happened and why.

Trump immediately announced his intent to nominate U.S. Ambassador to Norway Kenneth Braithwaite to replace Spencer as Navy secretary. Officials said Braithwaite has known Esper since they overlapped at the U.S. Naval Academy and West Point, respectively. Braithwaite is also said to be close with Trump ally David Urban, who graduated in the same West Point class as Esper, Secretary of State Mike Pompeo and two of Pompeo’s top officials.

And so the Trump administration revolving door continues to turn, the factions realign and everybody waits for the next battle. Spencer may get his honorable exit from the Trump administration. But remember — the official stories are just some of the pieces of this Trump puzzle.

Read more: