Washington (CNN) Defense Secretary James Mattis resigned Thursday on the heels of President Donald Trump's plans to withdraw troops from Syria, citing irreconcilable policy differences in a move that took Washington by surprise.

"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 in his letter to the President

Earlier Thursday, a senior administration official told CNN's Jake Tapper that Mattis was "vehemently opposed" to the Syria decision and a possible Afghanistan troop withdrawal.

Indeed, Mattis' resignation letter amounts to a rebuke of several of Trump's foreign policy views, with the outgoing defense secretary touting the importance of US alliances and of being "unambiguous" in approaching adversaries such as Russia and China. It is devoid of any praise for the President.

The resignation emerged at a chaotic moment in Trump's presidency: The US government is teetering on the edge of a government shutdown, the Trump administration is about to face the hot light of Democratic investigations and the President is grappling with the fallout of a series of firings and resignations. Trump, seeking to downplay the news, stepped out in front of Mattis' resignation, spinning it as a retirement.

Mattis did not explicitly cite his opposition to the President's planned withdrawal of US troops from Syria -- which caught US allies off guard -- but the retired four-star general was privately adamant in urging Trump against the pullback.

'They had differences'

JUST WATCHED Toobin: There are no more grown-ups in the room Replay More Videos ... MUST WATCH Toobin: There are no more grown-ups in the room 01:23

It was just the latest issue on which Mattis has sought to position himself as a bulwark against some of the President's rashest decisions, but his relationship with the President has grown increasingly fractured in recent months and his efforts to deter Trump on key issues less influential.

In his letter, Mattis pointedly stated that the strength of the US depends in part on the strength of its alliances around the globe, many of which have become notably frayed under Trump.

"One core belief I have always held is that our strength as a nation is inextricably linked to the strength of our unique and comprehensive system of alliances and partnerships. While the US remains the indispensable nation in the free world, we cannot protect our interests or serve that role effectively without maintaining strong alliances and showing respect to those allies," he added.

Mattis met with Trump one-on-one in the Oval Office, a senior White House official told CNN's Kaitlan Collins. Mattis told Trump he was going to be leaving and offered his resignation letter.

"They had differences on some issues," the official said.

Trump announced Mattis' departure in a tweet, saying, "General Jim Mattis will be retiring, with distinction, at the end of February, after having served my Administration as Secretary of Defense for the past two years."

The President touted the "tremendous progress" that has been made during Mattis' tenure at the helm of the Defense Department and thanked him for his service.

Trump said a successor "will be named shortly."

In a sign of the swift nature of the resignation, senior White House officials found out about it from the President's tweet, according to two officials. A senior administration official could not say if armed forces were told before the tweet.

Syria decision

JUST WATCHED CNN reporter: Mattis is falling on his sword Replay More Videos ... MUST WATCH CNN reporter: Mattis is falling on his sword 04:47

Mattis' resignation comes just a day after the President ordered the "full" and "rapid" withdrawal of US troops from Syria over the objections of Mattis, other senior officials and scores of lawmakers, who declared it a strategic blunder.

The announcement of his departure comes just over an hour after reports emerged that Trump may also be considering a drawdown of US troops in Afghanistan. Sources told CNN's Jake Tapper that the President has not yet made a final decision, but officials are concerned and convinced that he might do so, and soon.

Mattis is the latest senior administration to leave Trump's Cabinet, after former Attorney General Jeff Sessions was pushed out the day after the midterm elections in November, former Secretary of State Rex Tillerson was unceremoniously fired in March and national security adviser H.R. McMaster was replaced earlier this year.

But reaction to Mattis' departure was strikingly different.

In a statement, Senate Majority Leader Mitch McConnell emphasized the importance of maintaining "the post-World War II alliances" as well as "a clear-eyed understanding of our friends and foes."

"So I was sorry to learn that Secretary Mattis, who shares those clear principles, will soon depart the administration," the statement said. "But I am particularly distressed that he is resigning due to sharp differences with the president on these and other key aspects of America's global leadership.

"It is regrettable that the president must now choose a new Secretary of Defense. But I urge him to select a leader who shares Secretary Mattis's understanding of these vital principles and his total commitment to America's servicemembers."

Virginia Sen. Mark Warner, the top Democrat on the Senate Intelligence Committee, tweeted, "This is scary. Secretary Mattis has been an island of stability amidst the chaos of the Trump administration."

South Carolina Republican Sen. Lindsey Graham, a strong Trump supporter who opposes the President's decision to pull out of Syria, expressed "great sadness" over Mattis' resignation.

"He is one of the great military leaders in American history. He should be proud of the service he has rendered to President Trump and our nation," Graham tweeted.

Former Vice President Joe Biden tweeted that despite some disagreements with Mattis, "we shared the view — long-held by Democrats and Republicans in this nation — that respect for our allies and a commitment to the most important and effective alliances in history made America safer."

"It is clear this administration has abandoned those core American beliefs," Biden added . "Secretary Mattis' presence and his voice of reason and experience will be missed in the Pentagon and the Situation Room."

'A good guy'

Mattis' future was brought into question most recently after Trump, in an October interview with CBS' "60 Minutes," labeled him as "sort of a Democrat," adding that the retired general "may leave" and that "at some point, everybody leaves."

He also added that the 68-year-old Washington native was "a good guy" and the two had "a very good relationship."

Mattis, a bachelor, has been described as a "warrior monk," married to the Marines. He served in the first Gulf War and in Afghanistan. He once led the all-important US Central Command, which is in charge of the US military in the Middle East. He was also supreme allied commander of NATO.

After the 2016 election, Trump broke with protocol by tapping Mattis to be his secretary of defense, a position typically reserved for civilians.

In his first six months in office, Trump oversaw a steady transfer of power from the White House to the Pentagon, handing off several war-fighting authorities that previously rested in his hands -- and those of past presidents of both parties -- to the Pentagon and the commanders overseeing the US' military campaigns.

But while Mattis was widely considered one of Trump's most trusted advisers during his first year in office, his influence within the administration appeared to be waning in recent months as speculation swirled about a growing rift between the two men.

Bob Woodward's book "Fear: Trump in the White House," published in September, fueled that notion, detailing how senior aides, including Mattis, grew exasperated with the President and increasingly worried what they described as his erratic behavior, ignorance and penchant for lying.

Specifically, Woodward details several instances in which Mattis made disparaging comments about Trump and military actions he sought to take against Syria and North Korea.

One of the most striking accounts, according to Woodward, occurred after a charged meeting about South Korea, during which Trump wondered why the US backs Seoul. Woodward wrote that Mattis said Trump understands issues at the level of an elementary school student.

Mattis denied those assertions and the accounts detailed by Woodward's sources, including claims that he ignored or slow-rolled Trump's ideas.