Defense Secretary Mark Esper fired Navy Secretary Richard Spencer Sunday over his handling of the case of a Navy SEAL who posed for a photo next to an Islamic State terrorist’s corpse in Iraq, and the SEAL will be able to keep his Trident pin, a Pentagon spokesman said Sunday.

“Secretary of Defense Mark T. Esper has asked for the resignation of Secretary of the Navy Richard Spencer after losing trust and confidence in him regarding his lack of candor over conversations with the White House involving the handling of Navy SEAL Eddie Gallagher,” Pentagon spokesman Jonathan Hoffman said in a statement Sunday.

Controversy continued to swirl around whether or not the Navy would strip Gallagher of his Trident pin, ousting him from the prestigious SEALs after he was demoted from chief petty officer to a 1st class petty officer following his conviction in July. President Trump this month restored Gallagher’s rank and ordered that the Navy halt its internal review of Gallagher's actions from 2017 that resulted in a high-profile war crimes case, for which he was found not guilty of the murder of an Islamic State fighter in Iraq.

Esper and Chairman of the Joint Chiefs of Staff Mark Milley spoke to Trump on Friday with the intention of persuading the president to allow the Trident review board to go forward with its inquiry. Instead, Esper learned that Spencer previously and privately proposed to the White House – contrary to Spencer’s public position – to restore Gallagher’s rank and let him retire with his Trident pin, the Pentagon said. When Esper recently asked, Spencer confirmed that he'd never informed the defense secretary about his private proposal.

Spencer asked Trump to let the Navy review board go forward, promising that the board would, in the end, allow Gallagher to keep his Trident and rank, effectively alluding to his willingness to fix the results of the board usually comprised of the defendant’s peers, a senior U.S. official told Fox News. Trump rejected the offer and said, “no, we’re done,” prompting the president to write a series of tweets doubling down on his efforts to halt the review, the official added.

“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.”

Spencer’s ousting was not a consequence of standing up for military justice – but rather was for dishonesty and undermining the military justice system, the senior U.S. official told Fox News. He was fired for “lack of candor,” the official added.

Esper ordered that Gallagher be allowed to keep his Trident pin, noting that it would be nearly impossible for him to get a fair hearing from the military in light of recent events, a senior official said.

Esper suggested that Trump appoint Kenneth Braithwaite, the current U.S. ambassador to Norway and a retired Navy rear admiral, to replace Spencer, the Pentagon said. The president later tweeted Sunday evening that he would nominate Braithwaite for the position, writing, "A man of great achievement and success, I know Ken will do an outstanding job!"

TRUMP DECLARES NAVY WILL NOT TAKE AWAY EDDIE GALLAGHER'S SEAL TRIDENT, AS ATTORNEY BLASTS ADMIRAL

Trump also wrote that he "was not pleased" with the way Gallagher's trial was handled by the Navy.

"He was treated very badly but, despite this, was completely exonerated on all major charges. I then restored Eddie's rank. Likewise, large cost overruns from past administration's contracting procedures were not addressed to my satisfaction," Trump said. "Therefore, Secretary of the Navy Richard Spencer's services have been terminated by Secretary of Defense Mark Esper. I thank Richard for his service and commitment. Eddie will retire peacefully with all of the honors that he has earned, including his Trident pin."

The Washington Post was first to report the news of Spencer's ouster.

In a letter addressed to Trump after his termination, obtained by multiple news organizations, Spencer wrote that he "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."

He also added that the president "deserved and should expect" a Navy secretary "who is aligned with his vision," but added, "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."

Some Pentagon officials said they believed the Navy secretary’s resignation letter was drafted last week. Officials told Fox News there was no formal "order" from the president, as Spencer wrote in his letter, to keep Gallagher on the SEAL teams; Spencer may have drafted a resignation letter in anticipation of a potential written order demanding the Navy scrap the review board scheduled to meet next month.

Senate Armed Services Committee Chairman Jim Inhofe, R-Okla., said both Esper and Trump notified him that Spencer had been fired.

"Both Secretary Esper and President Trump deserve to have a leadership team who has their trust and confidence," Inhofe said in a statement. “It is no secret that I had my own disagreements with Secretary Spencer over the management of specific Navy programs, and I look forward to receiving and considering a nomination for the next Secretary of the Navy as soon as possible.”

Multiple Navy officials told Fox News that Spencer had threatened to resign if the military branch was not allowed to go through with the administrative review board on the Gallagher matter. Spencer, speaking at an international security forum in Canada on Saturday, denied that claim and said that he did not consider a tweet by Trump an order and would need a formal order to stop the Navy review board, scheduled to begin Dec. 2.

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

“I need a formal order to act,” Spencer said of Trump’s tweets, “I don’t interpret them as a formal order.”

The Navy on Wednesday had notified Gallagher that he will face the review board to determine if he should remain on the elite force.

“The president of the United States is the commander in chief. He’s involved in every aspect of government and he can make decisions and give orders as appropriate,” Spencer said.

Gallagher’s lawyers have accused the Navy of trying to remove the SEAL designation in retaliation for Trump’s decision to restore his rank.

Gallagher filed a complaint with the inspector general accusing Rear Adm. Collin Green, the Naval Special Warfare commander, of insubordination for defying Trump’s actions.

Speaking earlier Sunday on “Fox & Friends,” Gallagher repeated his argument that the Navy was acting in retaliation.

“They could have taken my Trident at any time they wanted,” he said. “Now they’re trying to take it after the president restored my rank.”

Gallagher said he wanted to be allowed to retire on Nov. 30 “with all the honors that I’ve earned, get back to my family.”

After Spencer's resignation and confirmation that he could keep his Trident pin and rank, Gallagher praised Trump in a statement to Fox News' Pete Hegseth.

"President Donald Trump, you have my deepest gratitude and thanks," Gallagher said. "You stepped in numerous times and showed true moral fiber by correcting all the wrongs that were being done to me. You are a true leader and exactly what the military and this nation needs. God bless you and your family."

Green also notified three SEAL officers who oversaw Gallagher during the deployment — Lt. Cmdr. Robert Breisch, Lt. Jacob Portier and Lt. Thomas MacNeil — that they are also being reviewed, according to U.S. officials. Removing their Trident pins means they will no longer be SEALs but could remain in the Navy.

CLICK HERE FOR THE FOX NEWS APP

A Navy source told Fox News that they “can’t see a world where they go forward” with the other 3 SEALS peer review board hearing, following the Gallagher fiasco. “We need to move on.”

The Navy has revoked 154 Trident pins since 2011.

Fox News' Lucas Tomlinson, Jennifer Griffin and The Associated Press contributed to this report.