President Trump said Thursday evening that Defense Secretary James Mattis will be retiring in February, in a shock announcement adding to the list of the president's outgoing Cabinet members after his second year in office.

Mattis will step down "with distinction" after serving in his role for two years, the president said on Twitter.

"During Jim’s tenure, tremendous progress has been made, especially with respect to the purchase of new fighting equipment," Trump tweeted. "General Mattis was a great help to me in getting allies and other countries to pay their share of military obligations. A new Secretary of Defense will be named shortly. I greatly thank Jim for his service!"

CLICK HERE TO GET THE FOX NEWS APP

A senior U.S. defense official told Fox News that Mattis was not pushed out of his role and this was not a forced resignation.

"He informed his staff after returning from the White House this afternoon," Pentagon spokesperson Dana White said.

Fox News is told that Mattis met with Trump at 3 pm and later called his staff together for a meeting a little after 5 pm.

Following the announcement, the Pentagon also released a copy of Mattis' signed resignation letter.

Mattis wrote that he has "been privileged to serve" in his role as defense secretary and acknowledged the department's record during his time there.

In his letter to Trump, Mattis acknowledged that a strong nation relies on a "comprehensive" network of alliances, and must be "resolute and unambiguous" in approaching countries with strategic differences, citing China and Russia.

"Because you have the right to have a Secretary of Defense whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position," Mattis wrote.

His departure date will be Feb. 28, 2019, which he noted should give the president and the department enough time to his replacement to be nominated and confirmed. He also pledged his "full effort to a smooth transition."

"I very much appreciate this opportunity to serve the nation and our men and women in uniform," Mattis concluded.

FORMER TRUMP ADMINISTRATION OFFICIALS: A LIST OF NOTABLE DEPARTURES

Word of Mattis' resignation comes a day after U.S. officials confirmed that Trump's administration is making plans to pull all 2,000 American troops out of Syria. And on Thursday, a senior U.S. official told Fox News that Trump is seriously considering a “significant drawdown” of U.S. troops who are stationed in Afghanistan.

Sen. Lindsey Graham, R-S.C., who earlier Thursday sparred with the president regarding the decision to pull U.S. troops from Syria, tweeted that it was "with great sadness" that he learned of Mattis' resignation, who he described as "one of the great military leaders in American history."

"General Mattis is a combination of intellect and integrity. He has been in the fight against radical Islam for decades and provided sound and ethical military advice to President Trump," Graham continued. "He is a role model for the concept of Duty, Honor, Country."

Sen. Chris Murphy, D-Conn., also took to Twitter, arguing that the resignation was a "national security crisis."

"A Secretary of Defense quitting over a public disagreement with a President whose foreign policy he believes has gone off the rails is a national security crisis," Murphy tweeted. "No way around it."

Fox News' Lucas Tomlinson and Jennifer Griffin contributed to this report.