President Trump's Navy Secretary Richard Spencer said he was fired in the controversy over a Navy SEAL because the president gave him an order he couldn't, "in good conscience," carry out.

Secretary Spencer's removal follows a dispute that began when the president reversed the Navy's demotion of Edward Gallagher, who was convicted of posing for a photo with a dead ISIS fighter in Iraq. Gallagher was also accused of murdering a prisoner of war, but was acquitted of that charge.

Secretary Of The Navy Richard Spencer Testifies To The Senate Armed Services Committee
Secretary of The Navy, Richard Spencer, testifies during a Senate Armed Services Committee hearing on Navy readiness on April 9, 2019 in Washington, DC. Alex Edelman / Getty Images

In a statement, Spencer's boss, Defense Secretary Mark Esper, said he fired Spencer "after losing trust and confidence in him regarding his lack of candor."

Either way, the case of the Navy vs. Edward Gallagher has now turned into a full-scale fiasco, complete with conflicting accounts of why the Navy secretary had to go, reports CBS News national security correspondent David Martin.

Spencer was fired a day after denying reports he might resign over the Gallagher affair. "I have not threatened to resign. I am here, I work at the pleasure of the president," he said in Nova Scotia during the Halifax International Security Forum.

Esper said that while Spencer had been publicly pushing for Gallagher's removal from the Navy, privately he had gone behind Esper's back to negotiate with the White House on ways to short-circuit disciplinary hearings against Gallagher.

Last week, the president tweeted that "The Navy will not be taking Gallagher's Trident pin" – the symbol of his status as an elite Navy SEAL.

Spencer said he needed to see an order in writing from the president before stopping Gallagher's appearance before a review board that could have kicked him out of the elite unit. "If the president requests to stop the process, the process stops," Spencer said.

But Spencer's resignation letter made it sound like he was fired before he could embarrass the president by resigning on principle. He wrote: "I cannot in good conscience obey an order that I believe violates the sacred oath I took."

For his part, President Trump tweeted he was "not pleased" with the way the Navy handled the Gallagher case, and with Spencer's inability to manage cost overruns on big ticket items like a new aircraft carrier.

That capped a day in which Gallagher appeared on Fox News and made openly insubordinate statements about his superior officers: "This is all about ego and retaliation. This has nothing to do with good order and discipline," he said.

It didn't end well for Spencer, but it did for Gallagher. Secretary Esper has directed that Gallagher be allowed to keep his Trident. And in a statement to Fox News last night, Gallagher thanked the president for stepping in multiple times and "correcting all the wrongs" done to him.

© 2019 CBS Interactive Inc. All Rights Reserved.