Defense Secretary Jim Mattis announced his resignation Thursday afternoon, sending President Donald Trump a letter that implicitly criticized the president’s military judgment.

In the letter, Mattis suggested Trump was not treating allies with respect and had not been “clear-eyed” about U.S. enemies and competitors.

“My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors are strongly held and informed by over four decades of immersion in these issues,” he wrote.

Mattis told the president in the letter that he should have a defense chief who shares his views.

“Because you have the right to have a Secretary of Defense whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position,” he wrote.

Many traditional U.S. allies have been frustrated by Trump’s open differences with them, and Mattis appeared to take the president to task for that in the letter.

“One core belief I have always held is that our strength as a nation is inextricably linked to the strength of our unique and comprehensive system of alliances and partnerships,” the general wrote.

“While the U.S. remains the indispensable nation in the free world, we cannot protect our interests or serve that role effectively without maintaining strong alliances and showing respect to those allies,” the letter said.

The president on Twitter portrayed the departure as a retirement.

“General Jim Mattis will be retiring, with distinction, at the end of February, after having served my Administration as Secretary of Defense for the past two years,” Trump wrote.

“During Jim’s tenure, tremendous progress has been made,” the president tweeted. “General Mattis was a great help to me in getting allies and other countries to pay their share of military obligations. A new Secretary of Defense will be named shortly. I greatly thank Jim for his service!”

The administration is now working with an acting attorney general while the interior secretary has recently resigned.

Congress passed a waiver to allow Mattis to serve as Secretary of Defense; a law bars newly retired military officers from heading up the Department of Defense.

Rep. Mac Thornberry, R-Texas, who chairs the House Armed Services Committee, referenced that move, which he called “an extraordinary action,” in praising Mattis. Thornberry said the only other time that had been done was when Gen. George C. Marshall was chosen as Secretary of Defense in the Truman administration.

“Speaking in support of the legislation on the House Floor I said, ‘I know of no one more respected, more admired in the field of national security today than General Mattis,'” Thornberry said in a statement Thursday. “His service as Secretary over the last two years has only added to the luster of his name.”