The retired Marine Corps general, who was known as a stabilising force in President Donald Trump’s Cabinet, will retire in February. He becomes the latest in a long list of high ranking Trump administration figures who have either quit or been fired. Mr Trump delivered the news via Twitter.
He said General Mattis would be retiring with “distinction” and thanked him for his service.
The announcement comes just a day after President Trump announced he had ordered the withdrawal of US forces from Syria – a move opposed by top military officials.
In his resignation letter, General Mattis said he was stepping down so Mr Trump could have a defence chief whose views align more closely with his own.
Speculation that he may not last long in his post grew in October when President Trump said in a CBS interview that the general was “sort of a Democrat” and might be leaving.
Announcing the departure on Twitter, Mr Trump said: “General Jim Mattis will be retiring, with distinction, at the end of February, after having served my Administration as Secretary of Defence for the past two years. During Jim’s tenure, tremendous progress has been made, especially with respect to the purchase of new fighting 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 Defence will be named shortly. I greatly thank Jim for his service!”
But Mr Mattis in his resignation letter explained he was leaving his post because he did not agree with the President’s decisions.
In particular, he stressed disagreement with Trump’s attitude towards international relations, and the importance of alliances.
He wrote: “We cannot respect those alliances without maintaining strong allies.”
Discussing Nato, he said: “Similarly I believe we must be resolute with those countries whose strategic interests are aligned with ours.”
He singled out Russia and China as having opposing views.