U.S. President Donald Trump speaks while Mark Esper, U.S. Secretary of Defense, listens during a ceremony for the establishment of a U.S. Space Command in the Rose Garden of the White House in Washington, D.C., U.S., on Thursday, Aug. 29, 2019.

WASHINGTON — Defense Secretary Mark Esper said Monday that President Donald Trump, in an extraordinary move, ordered the Pentagon to let a Navy SEAL convicted of combat misconduct retain his elite Trident pin.

The Navy's Trident pin designates a sailor as a SEAL.

Esper's comments came hours after the Pentagon fired Navy Secretary Richard Spencer amid controversy over the handling of Special Operations Chief Edward Gallagher's case.

Gallagher, 40, was demoted in rank and pay grade after being convicted by a military jury in July of illegally posing for pictures with the corpse of an ISIS fighter. He was acquitted of premeditated murder for allegedly killing a wounded captive during his 2017 deployment to Iraq.

Last week, Spencer said that Gallagher's membership in the SEAL community should be decided by a board of his peers. Trump had previously said that Gallagher's status must be restored.

Spencer had reportedly threatened to quit his post after Trump intervened in the case.

On Sunday evening, the Pentagon said in a statement that Esper had lost trust and confidence in Spencer and called for his resignation.

Spencer took parting shots at Trump in a letter saying that "the rule of law is what sets the United States apart from its adversaries" and that he and Trump "no longer share the same understanding of the key principles of good order and discipline."

Trump wrote in a string of tweets Sunday that Spencer was fired over the way the Navy handled Gallagher's case as well as cost overruns that were not addressed to his satisfaction. Ken Braithwaite, admiral and ambassador to Norway, will be nominated to replace Spencer, Trump wrote.

— Spencer Kimball contributed to this report from CNBC's global headquarters in Englewood Cliffs, New Jersey.