Washington: US Defence Secretary James Mattis has resigned after falling out with Donald Trump over the withdrawal of American troops from Syria and Afghanistan, saying in a parting letter that the President deserves someone atop the Pentagon “better aligned” with his views.

The retired Marine general’s announcement came on Thursday, a day after the Trump administration said that the full withdrawal of US forces from Syria was under way. Mattis said he would leave by the end of February.

Trump overruled his advisers, including Mattis over Syria troop withdrawal and declared victory over the Islamic State. However, the Pentagon and State Department for months have been saying the fight against the group in Syria was far from over, the Washington Post reported.

The President also ordered the Pentagon, against Mattis’ recommendation, to come up with a plan to pull out approximately half of the 14,000 American troops deployed in Afghanistan, a move likely to plunge the war-torn nation into further chaos.

Mattis released the parting letter after a face-to-face meeting with Trump in which the two men discussed their differences, a senior White House official said.

The retired general, in contrast to Trump, favoured international alliances and said that the US derives its strength from its relationships with allies and should treat them with respect. He also said the country must also be “clear-eyed” about threats, including from groups such as the Islamic State.

“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 the solidarity of our alliances,” Mattis wrote.

The Pentagon released the resignation letter moments after Trump announced on Twitter that Mattis would be leaving, saying the already retired Marine would “retire”. Trump made no mention of his differences in opinion with Mattis.

“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,” Trump tweeted.

“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,” he said.

Senator Tom Cotton, a Republican from Arkansas and Jack Keane, a retired Army general who was an early supporter of Trump, are possible replacements for Mattis, according to reports.

House Minority Leader Nancy Pelosi said she was “shaken” by the resignation and described it as “very serious for our country”.

Republicans were also dismayed by the decision. Senate Majority Leader Mitch McConnell said the US must maintain its carefully built alliances and a clear understanding of its friends and foes.

Mattis was seen as a bulwark against Trump’s “isolationist impulses” and extreme proposals. He served as a calm “reassurer-in-chief” while the President sent out provocative tweets, the Washington Post said.

His departure led to a chorus of concern about the President’s temperament and decision-making ability and injected new uncertainty into the administration’s approach to global threats.

A poll conducted in September found that nearly 90 per cent of US military officers had a favourable view of Mattis’ work.