US defence secretary Jim Mattis has resigned after clashing with President Donald Trump over the abrupt withdrawal of US troops from Syria and two years of deep disagreements over America’s role in the world.

Mr Mattis, perhaps the most respected foreign policy official in Mr Trump’s administration, will leave by the end of February after two tumultuous years struggling to soften and moderate the president’s hardline and sometimes sharply changing policies.

He told Mr Trump in a letter that he was leaving because “you have a right to have a secretary of defence whose views are better aligned with yours”.

Mr Mattis went to the White House with his resignation letter in hand to meet with the president and spoke to Mr Trump for about 45 minutes, according to officials.

There was no confrontation between the two men, the official said, and there was no one issue which caused the resignation. However, the official said Syria had likely been the last straw for Mr Mattis.

His departure was immediately lamented by foreign policy hands and members of congress on both sides of the aisle, who viewed the retired Marine general as a sober voice of experience in the ear of a president who has never held political office or served in the military.

Donald Trump
Donald Trump and Jim Mattis frequently disagreed over the US role in the world (AP)

Even Trump allies expressed fear over Mr Mattis’ decision to quit, believing him to be an important moderating force on the president.

“Just read Gen. Mattis resignation letter,” tweeted Florida senator Marco Rubio. “It makes it abundantly clear that we are headed toward a series of grave policy errors which will endanger our nation, damage our alliances & empower our adversaries.”

Mr Mattis did not mention the dispute over Syria in his letter or proposed deep cuts to US forces in Afghanistan, another significant policy dispute.

He noted his “core belief” that American strength is “inextricably linked” with the nation’s alliances with other countries, a position seemingly at odds with the “America First” policy of the president.

The defence secretary also said China and Russia want to spread their “authoritarian model” and promote their interests at the expense of America and its allies. “That is why we must use all the tools of American power to provide for the common defence,” he wrote.

The announcement came a day after Mr Trump surprised US allies and members of congress by announcing the withdrawal of all US troops from Syria, and as he continues to consider cutting in half the American deployment in Afghanistan by this summer.

The news coincided with domestic turmoil, Mr Trump’s fight with US congress over a border wall and a looming partial government shutdown.

The US president’s decision to pull troops out of Syria has been sharply criticised for abandoning America’s Kurdish allies, who may well face a Turkish assault once US troops leave, and had been staunchly opposed by the Pentagon.

Mr Mattis, in his resignation letter, emphasised the importance of standing up for US allies – an implicit criticism of the president’s decision on this issue and others.

Resignation letter
Mr Mattis’ resignation letter (AP)

The outgoing defence secretary wrote: “While the US remains the indispensable nation in the free world, we cannot protect our interests or serve that role effectively without maintaining strong alliances and showing respect to those allies.”

Last year, Republican senator Bob Corker – a frequent Trump critic – said Mr Mattis, along with White House chief of staff John Kelly and then-secretary of state Rex Tillerson, were helping “separate our country from chaos”.

Mr Tillerson was sacked early this year. Mr Kelly is to leave the White House in the coming days.

Mr Mattis’ departure has long been rumoured, but officials close to him have insisted that the retired Marine would hang on, determined to bring military calm and judgment to the administration’s often chaotic national security decisions and to soften some of Mr Trump’s sharper tones with allies.

Opponents of Mr Mattis, however, saw him as an unwanted check on Mr Trump.

The US president said a replacement would be chosen soon.