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!”

....equipment. 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! — Donald J. Trump (@realDonaldTrump) December 20, 2018

Trump and Mattis have reportedly been at odds recently over military issues, according to numerous published reports.

The president just this week announced he was pulling all U.S. troops out of Syria, a sudden policy shift that blindsided Congress and most senior officials at the Pentagon and State Department.

Sen. Lindsey Graham, R-S.C., said at a press conference earlier Thursday that Mattis told him he thought it is not the right time to leave Syria.

Previously, Trump pulled out of the Iran nuclear deal without consulting Mattis, who had to scramble to get the president on the phone before that formal announcement was made.

This past summer, Trump surprised Mattis again by pausing U.S. military exercises with South Korean in a concession to North Korean dictator Kim Jong Un.

A short time later, Mattis was blindsided by Trump again when the president directed the Pentagon to develop a sixth branch of the military to oversee space.

After Mattis announced his resignation, Graham, a member of the Armed Services Committee, on Twitter called him "one of the great military leaders" in U.S. history.

Senate Majority Leader Mitch McConnell, R-Ky., in a statement seemed to echo some of Mattis' comments about alliances in the letter.

"I believe it’s essential that the United States maintain and strengthen the post-World War II alliances that have been carefully built by leaders in both parties," McConnell said. "We must also maintain a clear-eyed understanding of our friends and foes, and recognize that nations like Russia are among the latter.

"I am particularly distressed that he is resigning due to sharp differences with the president on these and other key aspects of America’s global leadership," he continued, urging Trump "to select a leader who shares Secretary Mattis's understanding of these vital principles and his total commitment to America’s servicemembers."

Mattis' departure adds one more high-level position the president must fill.

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