In his resignation letter, Mattis, a former four-star Marine general, appeared to point to his policy differences with Trump, who has frequently clashed with US allies.
He told Trump in a letter that he was leaving because "you have a right to have a Secretary of Defense whose views are better aligned with yours".
Even so, most military experts say the Afghan military and police are not capable of taking on the Taliban by themselves, and a dramatic USA troop withdrawal would nearly certainly undercut efforts by US envoy Zalmay Khalilzad to open up talks with the insurgent Taliban.
Despite that report, Trump thanked Mattis for his service on Thursday and praised him for making a contribution to his administration.
Mattis explicitly advised Trump against the move, warning him it could cede power of Syria to Russian Federation or Iran or give ISIS a chance to regroup, according to reports. Anyone who respects Secretary Mattis, as I do, is bound to take his critique seriously and be concerned by it.
In a letter to Trump, the 68-year-old Pentagon chief said his political outlook, which cherishes traditional alliances, could no longer be reconciled with that of the president, who has poured scorn on longstanding partnerships and repeatedly sought closer ties with Russian Federation.
Allies must be treated with respect and the U.S. He did not retire, despite a tweet from President Trump.
But questions about Mattis' influence grew as the president made decisions that deviated from his advice, such as pulling out of the nuclear deal with Iran, relocating the U.S. Embassy in Israel to Jerusalem and launching a new Space Force that many military leaders saw as unnecessary and distracting.
The news is certain to shock USA military allies, already bewildered by what they see as Trump's unpredictable, go-it-alone approach to global security, and raises questions about whether Mattis' successor will be as steadfast about traditional treaty commitments, including to NATO.
"Secretary Mattis has been an island of stability amidst the chaos of the Trump administration".
In a letter announcing his retirement, Mattis said it was his core belief that the United States needs to maintain strong alliances and show respect for allies.
But his exit has always been rumored, as clashes with Trump over foreign policy have increased in recent months.