WASHINGTON - Defense Secretary Mark Esper on Monday explained why he ousted his Navy secretary, saying he was "flabbergasted" to learn that Richard Spencer tried to make a secret deal with the White House involving a Navy SEAL accused of war crimes.

Esper said that without his knowledge, Spencer promised the White House that the SEAL could retire as a member of the elite force if President Donald Trump stayed out of the case. Although that outcome aligned with Trump's wishes, Esper said he and Gen. Mark Milley, the chairman of the Joint Chiefs of Staff, felt "blindsided" by Spencer's back-channel conversations.

"First, we have a chain of command that should be followed and that chain of command must be kept informed," he said. "Second, once we agree on a position we stick to it and support it both in private and public."

Esper, speaking to reporters at the Pentagon, also said Spencer's plan contradicted what he had told Esper and other senior defense officials in recent days - that he was considering resigning if Trump forced the issue.

As a result, the defense secretary said, Spencer had to go.

On Monday night, Spencer defended his actions in an interview with CBS News. In his first comments since being removed, he said Trump's intervention on behalf of Chief Petty Officer Edward Gallagher sends a message to U.S. troops that they can "get away" with bad behavior.

"We have to have good order and discipline," Spencer said. "It's the backbone of what we do."

Spencer said that "I will take the bad on me" for making the offer to the White House without Esper's knowledge, but that Esper's chief of staff, Eric Chewning, was informed. The Pentagon press secretary, Alyssa Farah, denied that anyone on Esper's staff was aware that Spencer had discussed any such deal with the White House senior staff.

Spencer's dismissal is the latest issue to roil the Pentagon in relation to Trump's Nov. 15 decision to intervene in three high-profile war crimes cases, including Gallagher's, despite opposition from senior Defense Department officials.

Since then, the Navy has convened review boards to decide whether to eject four Navy SEALs from the force, the Pentagon has tried to talk the president out of getting further involved, and White House officials have questioned Esper's loyalty to Trump, according to several administration officials, who spoke on the condition of anonymity because of the sensitivity of the issue.

It also remains uncertain how the Army will handle Trump's intervention in the case of the two soldiers he pardoned, and how a president deeply interested might react.

The situation in the Navy began a new slow boil after Trump's reinstated the rank of Gallagher, who was acquitted of murder in July but convicted of posing with the corpse of an Islamic State fighter and demoted. Murder allegations were brought against him by several of his SEAL teammates, but the case fell apart at trial after another SEAL testified under immunity that he actually had killed the prisoner in question.

After Trump intervened on behalf of Gallagher and reinstated his rank, Rear Adm. Collin Green, the commander of Naval Special Warfare Command, notified the SEALs involved that he would convene review boards to assess the fitness of Gallagher and three officers who oversaw him in Iraq to keep their Trident, the insignia representing their connection to the SEALs.

Spencer's private offer to the White House occurred about the same time, while Esper was traveling in Asia

It wasn't clear on Monday whether Trump considered Spencer's alleged proposal, but the president made his position clear Thursday.

"The Navy will NOT be taking away Warfighter and Navy Seal Eddie Gallagher's Trident Pin," the president said in a tweet. "This case was handled very badly from the beginning. Get back to business!"

Trump sent the tweet because he believed the military was trying to embarrass him, a senior administration official said. After he did so, changing the president's mind was a "top priority" for Pentagon leadership, said three administration officials with knowledge of the situation.

Esper said on Monday that Army and Navy leaders agreed a few weeks ago that the Pentagon should rely on the military's legal system and administrative processes to resolve the cases. A day after the news broke that Trump might soon intervene, Esper, Milley, Army Secretary McCarthy and other defense officials sought to change the president's mind, several officials familiar with the situation have said.

Esper said he learned from a senior White House official on Friday after meeting with Trump that Spencer had offered an alternative option.

Esper and Milley had just made the case to Trump that he should let the system run its course and told him that if Gallagher lost his Trident, the president could reverse the decision as commander in chief, according to an administration official. They left the White House believing that the president might agree to wait, the official said, even if the president might reverse it.

Esper said that he told Trump on Saturday that he would ask for Spencer's resignation and that the president supported his decision. On Sunday, Trump directed Esper to allow Gallagher to retire as a SEAL, and Esper said he would do so.

Esper said he believes doing so is a lawful order, and therefore he must either follow it or resign. He also made the case that leaving the issue to be sorted out by the review board comprising Navy SEALs would be unfair to them.

"While I believe strongly in process, the issue should not now be thrown into the laps of a board of senior [enlisted sailors] to sort out," Esper said. "As professional as they are, no matter what they would decide they would be criticized from many sides, which would further drag this issue on, dividing the institution. I want the SEALs and the Navy to move beyond this now and get fully focused on their warfighting mission."

In a letter to Trump acknowledging his dismissal, Spencer said he tried to ensure that legal proceedings were fair.

"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," Spencer wrote. "I cannot in good conscience obey an order that I believe violates the sacred oath I took in the presence of my family, my flag and my faith to support and defend the Constitution of the United States."

Trump tweeted about Spencer on Sunday night after his termination letter began circulating, saying he was not happy with the Navy's handling of the Gallagher case or cost overruns on some unnamed contracts. Spencer's letter annoyed the president, who wanted to frame the issue in his own terms, another administration official said.

Esper said the Gallagher case has "dragged on for months, and it has distracted too many."

"If folks want to criticize anyone about reaching down into the administrative processes, then simply blame me," he said. "I'm responsible at this point. It's not where I prefer to be, but I'll own it."

Esper declined to name the senior White House official who revealed Spencer's proposal to him, but he said Spencer was "forthright" about it when he questioned him about it.

The defense secretary said Monday that he cannot reconcile Spencer's comments, including in his termination letter, with his private promise to ensure that Gallagher would be able to retire as a SEAL.

"This is my issue with trust and confidence," Esper said. "I and General Milley and others had been acting on good faith and confidence with regard to rules and agreements we set forth. And then to find out that for some manner of time our position was being undermined and that at some point in time somebody in their chain of command might be asked to compromise their integrity and bend the rules? My view has been, let the process play itself out."

It was not clear whether the three SEAL officers also facing review boards in the case - Lt. Cmdr. Robert Breisch, Lt. Jacob Portier and Lt. Thomas MacNeil - will receive a reprieve. Esper said he has asked Navy leaders to bring him a recommendation.

The Army, meanwhile, has stayed quiet about how it will handle Army Maj. Mathew Golsteyn and dismissed 1st Lt. Clint Lorance, the soldiers Trump pardoned. Golsteyn was due to be tried next year on a murder charge in the case of a suspected Taliban bomb-maker, while Lorance was convicted in 2013 in the murder of two unarmed Afghans.

Golsteyn is seeking the reinstatement of his Special Forces tab and the pinning of a Distinguished Service Cross, which is one step down from the Medal of Honor. The Army revoked the tab and a Silver Star awarded to Golsteyn after the investigation began. The Silver Star had been approved for an upgrade.

Esper said on Monday that he is "going to take this one step at a time," and that he still is focusing on Gallagher's case.

This article was written by Dan Lamothe and Josh Dawsey, reporters for The Washington Post.