Image copyright Reuters Image caption Navy Secretary Richard Spencer said he and Trump did not have the same view of "discipline"

US Navy chief Richard Spencer has been fired over his handling of the case of a Navy Seal demoted for misconduct.

The case of Edward Gallagher, who was convicted for posing with a corpse, had sparked tensions between US President Donald Trump and military officials.

The navy officer had been due to face a disciplinary review where he could have been stripped of his Seals membership.

There have been differing accounts as to why Richard Spencer was asked to resign.

US Defence Secretary Mark Esper said he had lost confidence in the navy secretary because his private conversations with the White House contradicted his public position.

However, Mr Trump said he was not happy with "cost overruns" and how Chief Petty Officer Gallagher's trial was run, and suggested this was why Mr Spencer was fired.

Meanwhile, in a strongly worded letter, Mr Spencer said it was apparent that he and Mr Trump did not have the same view of "good order and discipline".

"The lives of our Sailors, Marines and civilian teammates quite literally depend on the professional execution of our many missions," he said.

Mr Trump has drawn criticism from parts of the military after pardoning army officers convicted of war crimes.

How did we get here?

Gallagher was accused of stabbing an unarmed 17-year-old Islamic State group prisoner to death and randomly shooting civilians while serving in Iraq in 2017.

He was acquitted of those charges and convicted only of the lesser charge of posing with the IS prisoner's corpse.

For that, he was demoted, but President Trump later reinstated his rank.

Gallagher was formally notified by navy leaders last week that he would face a disciplinary review which could result in his being stripped of his membership of the Seals.

Mr Trump tweeted his disapproval of this on Thursday, saying the navy would "NOT be taking away Warfighter and Navy SEAL Eddie Gallagher's Trident Pin".

Why was Spencer fired?

On Sunday, the defence department said Mr Esper had asked Mr Spencer to resign due to "his lack of candour".

Mr Spencer had made private proposals to the White House, which he did not share with Mr Esper, and had contradicted his public position, Pentagon spokesman Jonathan Hoffmann said in a statement.

According to the Washington Post, Mr Spencer had privately suggested to White House officials that if they did not interfere with proceedings against Edward Gallagher, he would ensure that the officer retired as a Navy Seal.

However, the New York Times quoted defence officials as saying Mr Trump had been angered by reports that Mr Spencer had threatened to resign if the president intervened in the case.

Mr Trump tweeted on Sunday he was not happy with how the navy had handled Gallagher's trial, and high costs in the navy's contracting procedures.

"Therefore, Secretary of the Navy Richard Spencer's services have been terminated," he said, adding: "Eddie will retire peacefully with all of the honours that he has earned, including his Trident pin."

In his resignation letter to President Trump, Mr Spencer wrote: "The rule of law is what sets us apart from our adversaries. Good order and discipline is what has enabled our victory against foreign tyranny time and again."

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

"I cannot in good conscience obey an order that I believe violates the sacred oath I took."

Senior Democratic Senator Chuck Schumer commended Richard Spencer for "standing up to President Trump when he was wrong, something too many in this administration and the Republican Party are scared to do".

What does this mean for Gallagher?

Image copyright Reuters Image caption Navy Seal Special Operations Chief Edward Gallagher was accused of war crimes in Iraq

Mr Esper has instructed that Gallagher be allowed to retire as a Navy Seal, retaining his Trident pin which symbolises membership of the elite unit.

While Mr Esper had wanted the disciplinary process to "play itself out objectively", he had decided to let Gallagher keep his pin "given the events of the last few days", defence spokesman Jonathan Hoffman said in a statement.

He had concluded Gallagher could not receive fair treatment in his case from the navy, AP news reported.

"Secretary Esper will meet with Navy Under Secretary (now Acting Secretary) Thomas Modley and the Chief of Naval Operations, Admiral Michael Gilday, on Monday morning to discuss the way ahead," the statement said.

Gallagher told the conservative Fox News channel on Sunday that he intends to retire next Saturday.

You might also be interested in: