Navy SEAL Eddie Gallagher thanked President Trump for intervening on his behalf Sunday, shortly after the Pentagon announced the resignation of Secretary of the Navy Richard Spencer.

Defense Secretary Mark Esper asked Spencer to resign, saying the Navy secretary secretly tried to broker a deal with the White House that would allow Gallagher to retire with his SEAL Trident intact. The Navy's review of Gallagher's place in the SEAL community was largely seen as an impediment to his ability to retire with his full rank and status. In a lengthy statement obtained by the Washington Examiner, Gallagher thanked God, his supporters, and Trump.

"President Donald Trump, you have my deepest gratitude and thanks," Gallagher said. "You stepped in numerous times and showed true moral fiber by correcting all the wrongs that were being done to me."

Trump first intervened on Gallagher's behalf in April, when he ordered the SEAL, who was accused of war crimes, to be released from the Navy brig in March. Following the trial, Trump rescinded medals that were given to the Navy prosecution team. The president restored Gallagher's rank earlier this month after the Navy busted him down to petty officer. When the Navy announced it possibly would pull Gallagher's Trident, Trump appeared to reverse the decision, telling Navy leaders to "Get back to business!"

In a statement regarding Spencer, the Pentagon announced that Esper has resolved the question of Gallagher's Trident. "... given the events of the last few days, Secretary Esper has directed that Gallagher retain his Trident pin," read the announcement by Department of Defense spokesman Jonathan Hoffman.

With Spencer's ouster effective immediately, Gallagher praised the president.

"You are a true leader and exactly what the military and this nation needs," Gallagher said. "God bless you and your family."

The embattled SEAL expects to retire by Nov. 30, said his lawyer, Tim Parlatore.

When asked if Gallagher's spat with the Navy is over, Parlatore told the Washington Examiner, "I hope. I sincerely hope."

[ Related: ‘Ego and retaliation': SEAL Eddie Gallagher blasts Navy secretary for ‘meddling’ in his case]