A clash between President Donald Trump and Navy leadership over a SEAL accused of war crimes devolved into chaos over the weekend — ending with Navy Secretary Richard Spencer tendering his resignation.

The leaders involved all have different accounts of what happened, but all versions begin with Trump’s decision to pardon Navy SEAL Chief Petty Officer Edward Gallagher.

Earlier this month, Trump pardoned Gallagher, who was accused in 2017 of killing a prisoner and committing other war crimes. In July, a military jury convicted him of just one minor count, that stemmed from the SEAL posing for a photo with the corpse of a teenage ISIS fighter. Trump cleared Gallagher of that charge and restored his rank.

But last week, the Navy let Gallagher know he’d face a review board and it was expected that he’d be booted from the elite force. Trump took exception and tweeted that he wouldn’t let leadership take Gallagher’s Trident pin, which signifies membership in the SEALs.

Defense Secretary Mark Esper said in a statement Sunday that Spencer had privately approached the White House to make a deal: He’d make sure Gallagher retired with his Trident if Trump let the disciplinary process go forward. In that statement, Esper announced that he’d asked for Spencer’s resignation.

"I am deeply troubled by this conduct shown by a senior DOD official," Esper said. "Unfortunately, as a result, I have determined that Secretary Spencer no longer has my confidence to continue in his position. I wish Richard well."

Esper’s statement pointedly highlighted the fact that the deal Spencer proposed was “contrary to Spencer's public position”: He had said publicly the review board process should be allowed to play out, which would likely have resulted in Gallagher losing his place in the SEALs.

By Sunday evening, Trump had waded back into the mess, adding his conflicting story to the mix.

Trump thanked Spencer on Twitter for his “service & commitment,” while also claiming Spencer was forced out over the Navy’s handling of the Gallagher case and unspecified “cost overruns.” Spencer, meanwhile, has said he was handed an order he believed violated “the sacred oath” he took to uphold good order and discipline. And finally, Esper claimed he fired Spencer over the deal he privately attempted to make with the White House.

Spencer had angered Trump by publicly disagreeing with the president over his decision to intervene in Gallagher’s case, and had threatened to quit. Spencer’s friends cited those reasons for his departure and disagreed with the way Esper characterized Spencer’s actions, the New York Times reported.

“The lives of our sailors, Marines, and civilian teammates quite literally depend on the professional execution of our many missions, and they also depend on the ongoing faith and support of the people we serve and the allies we serve alongside,” Spencer wrote in his resignation letter, which was released Sunday.

He added: “Unfortunately, it has become apparent that in this respect, 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.”

Gallagher is expected to keep his Trident after the chaos of the last few days. While ultimately acquitted of most charges, he was accused of killing a prisoner of war with a hunting knife and firing his sniper rifle at civilians.