US President Donald Trump speaks as Defense Secretary James Mattis (L) looks on during a meeting with senior military leaders in the Cabinet Room of the White House on October 5, 2017.

James Mattis stepped down as President Donald Trump's secretary of Defense on Thursday.

The president announced on Twitter that the retired general would depart the administration in February.

@realDonaldTrump: 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. During Jim's tenure, tremendous progress has been made, especially with respect to the purchase of new fighting...

@realDonaldTrump: ....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!

In a letter addressed to Trump, Mattis said that "because you have a right to have a Secretary of Defense whose views are better aligned with yours" on a number of subjects, "I believe it is right for me to step down from my position."

In his letter, Mattis cited the importance of US alliances, particularly NATO, and said the US must stand 'resolute and unambiguous' in the face of authoritarian countries such as China and Russia.