President Donald Trump said Wednesday that he essentially "fired" Jim Mattis as secretary of defense, criticizing his service.

"What's he done for me? How had he done in Afghanistan? Not too good," Trump said at a Cabinet meeting.

President Donald Trump said Wednesday that he essentially "fired" Jim Mattis as secretary of defense, criticizing his service in the Marine Corps and his two years leading the Defense Department.

"What's he done for me? How had he done in Afghanistan? Not too good," Trump said at a Cabinet meeting, according to Bloomberg News. "As you know, President Obama fired him, and essentially so did I," he added, contradicting an earlier statement.

"I think I would've been a good general, but who knows," said the president, who has not served in the military and sought five deferments during the Vietnam War.

Plans for Mattis to step down as the defense secretary were first announced in a presidential tweet that said the revered former Marine general was retiring.

Mattis said in his resignation letter, though, that he resigned over policy differences with the president.

"Because you have the right to have a Secretary of Defense whose views are better aligned with yours ... I believe it is right for me to step down from my position," he said.

The final straw for Mattis was said to be Trump's decision to abruptly withdraw from Syria, leaving the remainder of the fight against the terrorist group ISIS to Turkey and the Kurdish fighters the US military has partnered with, and whom Turkey has seen as a threat.

Mattis ended a legendary 44-year career in the Marine Corps in 2013 as the general in charge of US Central Command. He was reportedly forced into retirement early by the Obama administration for taking a hard line on Iran.

Read more: 19 unforgettable quotes from legendary Marine Gen. Jim 'Mad Dog' Mattis, who just quit as Trump's defense secretary

While Mattis was initially expected to serve as the defense secretary until the end of February, Trump forced him out early, tweeting that Patrick Shanahan, the deputy secretary of defense, would take over as acting secretary on January 1.

In a string of tweets on New Year's Eve, Trump trashed "failed Generals" who dared criticize his policy decisions, an apparent shot at retired Gen. Stanley McChrystal.