Secretary of Defense James Mattis is resigning, effective at the end of February.

President Trump announced that Mattis is retiring in a series of tweets on Thursday.

While the president said Mattis is retiring, Mattis resigned because he felt Trump needs a secretary of defense whose views were more closely aligned with those of the president.

President Donald Trump announced via Twitter on Thursday that Secretary of Defense James Mattis will be stepping down at the end of February.

"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," the president tweeted.

"During Jim’s tenure, tremendous progress has been made, especially with respect to the purchase of new fighting equipment," Trump added. "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!"

Read more: Trump just radically upended US Syria policy despite repeated warnings that doing so could be disastrous

While the president said Mattis is retiring, Mattis' resignation letter, a glaring critique of the presidency, clearly says that he is stepping down because of a difference of views between himself and the president, particularly when it comes to the security of international order, the treatment of allies, and the handling of American adversaries.

"My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors are strongly held and informed over four decades of immersion in these issues," Mattis said. "We must do everything possible to advance an international order that is most conducive to our security, prosperity and values, and we are strengthened in this effort by our alliances."

"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, suggesting that Trump does not share the same beliefs the secretary outlined in his letter.

The sudden, but not completely unexpected, announcement comes after Trump ignored the guidance of top advisers, Mattis included, and decided to withdraw US forces from Syria. Furthermore, there are now reports that the president is actively considering withdrawing as many as 3,000 of the 14,000 troops in Afghanistan.