Mattis, 68, had said he would leave at the end of February to allow a smooth transition for the next chief of the world's top military power, but Trump - who was reportedly upset over media coverage of the stinging resignation letter submitted by the defense secretary - moved up the timetable.
Trump likely to announce replacement for Mattis
"I am pleased to announce that our very talented Deputy Secretary of Defense, Patrick Shanahan, will assume the title of Acting Secretary of Defense starting January 1, 2019," the Republican leader tweeted.
"Patrick has a long list of accomplishments while serving as Deputy, & previously Boeing. He will be great!"
Trump initially praised Mattis in a tweet announcing his departure, saying that he was retiring "with distinction" and that "during Jim's tenure, tremendous progress has been made."
But Trump changed tone two days later, writing on Twitter that he had given Mattis a "second chance" after he was "ingloriously" fired by president Barack Obama, and appearing to take aim at a line from the Pentagon chief's resignation letter about respecting allies.
"Allies are very important-but not when they take advantage of US," Trump wrote.
The announcement that Mattis would leave the administration came just after Trump stunned Washington and allies abroad in declaring that US troops would leave Syria and significantly withdraw from Afghanistan.
Mattis and others had strongly counseled the often-impulsive president against those moves - and the decorated retired general did little to hide his disagreement with Trump.
"Because you have the right to have a secretary of defense whose views are better aligned with yours," Mattis said in his resignation letter, "I believe it is right for me to step down from my position."
US envoy to anti-IS coalition resigns after Trump's Syria decision
"My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors are strongly held and informed by over four decades of immersion in these issues," Mattis wrote.
Mattis's announced exit was soon followed by that of another top official, with Brett McGurk, the US envoy to the international coalition against the Islamic State militant group, moving up his departure from February to the end of the year.
Trump took to Twitter to criticize McGurk, referring to him as a "grandstander" who was quitting just before his time was up.
Unlike Mattis, Shanahan has never served in the military and has spent most of his career in the private sector.
He spent over three decades working for aircraft giant Boeing, including as vice president and general manager of Boeing Missile Defense Systems, before moving to the Pentagon as deputy in 2017.
Until Trump finds a permanent defense leader, Shanahan will lead plans for US troops to leave Syria along with a significant drawdown in Afghanistan, both of which critics worry will leave conflict-racked regions at risk of continued and potentially heightened bloodshed.
US to install observation posts on Syria-Turkey border: Mattis
Mick Mulvaney, who will soon leave his post as White House budget director to serve as Trump's chief of staff, told ABC on Sunday Trump will not change his mind about the withdrawal, despite this week's protest resignations.
"I think the president has told people from the very beginning that he doesn't want us to stay in Syria forever. You're seeing the end result now of two years' worth of work."
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ