Washington (AFP) - Defense Secretary Jim Mattis bade farewell to the Pentagon on Monday, telling the US military to "hold fast" after he quit over a series of fundamental differences with President Donald Trump.

Mattis resigned December 20, after 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," 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."

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," the former Marine Corps general 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."

- 'Difficult circumstances' -

Mattis was followed in his resignation by Brett McGurk, the US special representative to the coalition fighting the Islamic State movement, which Trump declared to be defeated.

Just days before Trump announced the Syria withdrawal on Twitter, McGurk addressed a news conference in which he assured that the United States would not "just pick up and leave" Syria, warning of the risks that the Islamic State would return.

On his last day in office Monday, McGurk, a Middle East troubleshooter under former presidents George W. Bush and Barack Obama, struck a similar tone to Mattis.

"I wish my former civilian and military colleagues well as they work under extremely difficult circumstances to protect the interests of our great country," McGurk tweeted.

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

Story continues

Trump was reportedly angered by news coverage of Mattis's stinging resignation letter, which 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 January 1, Patrick Shanahan will be acting defense secretary, moving up from his position of deputy.

On Monday, Trump appeared to soften his stance on Syria, saying troops would be sent home "slowly" while still fighting the Islamic State group.