Defense Secretary Mark Esper forced out Richard Spencer, the secretary of the Navy, over his handling of a Navy SEAL whose demotion for a war crimes charge had sparked objection from President Donald Trump. 

Esper asked for Spencer's resignation "after losing trust and confidence in him regarding his lack of candor" because he failed to tell Esper of a "private proposal" he made to the White House that would have allowed Navy Chief Petty Officer Eddie Gallagher to keep his rank and SEAL status, Pentagon spokesman Jonathan Hoffman said in a statement. 

"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."

Opinion:Do Navy leaders have a 'duty to disobey' Trump in Gallagher case?

In a letter submitted Sunday, Spencer did not say he resigned and instead wrote, "I hereby acknowledge my termination."

Spencer did not address Esper's charge of going over his head but said it had been "the extreme honor of a lifetime to stand alongside the men and women of the Navy and Marine Corps." He said his departure was due to the fact that he and Trump "no longer share the same understanding" of the importance of military justice. 

On Nov. 15, Trump reversed the demotion of Gallagher, who had been acquitted of stabbing an Islamic State prisoner and killing Iraqi civilians, but was convicted of posing with for a photo with a corpse. The following week, the Navy announced it would review Gallagher's status as a SEAL, which could have led to him losing his "Trident," the symbol of membership in the elite group of special operations troops. 

In a tweet at the time, Trump indicated he did not want the review to take place and stated, "The Navy will NOT be taking away Warfighter and Navy Seal Eddie Gallagher’s Trident Pin." 

Going to prison? Chinese woman convicted of trespassing at Donald Trump's Mar-a-Lago resort faces up to 6 years in prison

"This case was handled very badly from the beginning. Get back to business!" he said. 

On Saturday, Spencer denied reports that he had threatened to resign over Trump's intervention in the Gallagher case. 

While Esper said Spencer was pushed out because of his alleged undisclosed talks with the administration, Trump said in a tweet on Sunday that he had Spencer fired because he "was not pleased with the way that Navy Seal Eddie Gallagher’s trial was handled by the Navy" and because of "large cost overruns from past administration's" that "were not addressed to my satisfaction." 

"I thank Richard for his service & commitment," Trump said. "Eddie will retire peacefully with all of the honors that he has earned, including his Trident Pin." 

Spencer, however, indicated his departure was rooted in the disagreement over the Gallagher case. 

"The rule of law is what sets us apart from our adversaries," Spencer said in his letter. "The Constitution, and the Uniform Code of Military Justice, are the shields that set us apart, and the beacons that protect us all." 

"Unfortunately, it has become apparent 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. 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," he wrote. 

Spencer said Trump "deserves and should expect a Secretary of the Navy who is aligned with his vision for the future of our force generation and sustainment" and acknowledged his termination. 

According to the Pentagon, "Spencer had previously and privately proposed to the White House – contrary to Spencer's public position – to restore Gallagher's rank and allow him to retire with his Trident pin."

The statement said Esper always thought "the process should be allowed to play itself out objectively and deliberately, in fairness to all parties. However, at this point, given the events of the last few days, Secretary Esper has directed that Gallagher retain his Trident pin." 

Navy Under Secretary Thomas Modley will become the acting secretary of the Navy. Trump said he plans to nominate U.S. Ambassador to Norway Ken Braithwaite to become Spencer's permanent replacement. Braithwaite is a business executive and retired rear admiral. He served as a Navy aviator, whose missions included tracking Soviet submarines, before serving as an information officer. 

Contributing: Tom Vanden Brook and David Jackson, USA TODAY; The Associated Press