Former US defence secretary Jim Mattis bade farewell to the Pentagon, telling the US military to "hold fast" after he quit over a series of fundamental differences with President Donald Trump.

Mr Mattis resigned on 20 December, after Mr Trump stunned the US establishment by ordering a full troop withdrawal from Syria.

"Our Department is proven to be at its best when the times are most difficult," Mr Mattis said in a brief memo to the Pentagon, an apparent reference to the turmoil in Washington.

"So keep the faith in our country and hold fast, alongside our allies, aligned against our foes."

Mr Mattis, a scholar who frequently backs his views with historical anecdotes, also quoted a telegram President Abraham Lincoln sent to General Ulysses Grant in February 1865, near the end of the American Civil War.

"Let nothing which is transpiring, change, hinder, or delay your military movements, or plans," Mr Mattis quoted Lincoln as saying.

He added that he was confident military members are "undistracted from our sworn mission to support and defend the Constitution while protecting our way of life."

Mr Mattis had initially been due to leave the Pentagon at the end of February, but Mr Trump brought the date forward by two months.

Read More: 

Mattis resignation letter reveals chaos at White House
Mattis to step down as US Defense Secretary 
Trump pushes Mattis out early, says Shanahan will take over 

The president was reportedly angry over news coverage of Mr Mattis's stinging resignation letter that laid bare his fundamental disagreements with the president.

In that letter, 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 Russia.

As of 1 January, Patrick Shanahan will become acting defence secretary, moving up from his current position of deputy.

On Syria, Trump today appeared to soften his stance, saying troops would only be sent home "slowly" while still fighting the so-called Islamic State group.