Ousted Navy Secretary Richard V. Spencer sharply criticized President Trump’s “shocking and unprecedented intervention” in the case of a Navy SEAL accused of war crimes in Iraq, saying Trump’s efforts underscored that the president “has very little understanding” of the military.

Trump “involved himself in the case almost from the start” by publicly and privately advocating for Chief Petty Officer Edward Gallagher — an irregular move by the president to intervene in a “low-level review,” Spencer wrote in an opinion column published Wednesday in The Washington Post.

Spencer’s opinion piece drew criticism on social media from the president’s supporters and Gallagher’s defenders, who blamed the former Navy secretary for putting his own spin on his efforts to defy the wishes of the nation’s commander in chief.

Spencer was forced out over his handling of the case. Gallagher was acquitted of murder but convicted of bringing discredit to the armed services after posing with the corpse of an Islamic State prisoner.

Trump intervened to move Gallagher to less restrictive confinement before the trial began, and reversed Gallagher’s demotion and restored his rank after the verdict was delivered, Spencer wrote.

Spencer said he objected to Trump’s involvement but was overridden. He said he believed “that Trump’s interest in the case stemmed partly from the way the defendant’s lawyers and others had worked to keep it front and center in the media.”

“It was also a reminder that the president has very little understanding of what it means to be in the military, to fight ethically or to be governed by a uniform set of rules and practices,” Spencer wrote.

Spencer made a private proposal to the White House, which he said was an effort to fend off further involvement by the president while a review board worked to determine whether Gallagher would remain in the elite force.

He did so without consulting Defense Secretary Mark T. Esper, Spencer wrote, which ultimately led Esper to ask for Spencer’s resignation.

“That was, I see in retrospect, a mistake for which I am solely responsible,” Spencer wrote.

In the piece, Spencer defended the “system of military justice.”

“Americans need to know that 99.9 percent of our uniformed members always have, always are and always will make the right decision,” he wrote. “Our allies need to know that we remain a force for good, and to please bear with us as we move through this moment in time.”