WASHINGTON — Jim Mattis, the four-star Marine general turned defense secretary, resigned on Thursday in protest of President Trump’s decision to withdraw 2,000 American troops from Syria, where they have been fighting the Islamic State.
Mr. Trump announced the resignation in two tweets Thursday evening, and said Mr. Mattis will leave at the end of February.
Officials said Mr. Mattis went to the White House on Thursday afternoon in a last attempt to convince Mr. Trump to keep American troops in Syria. He was rebuffed, and told the president that he was resigning as a result.
Hours later, the Pentagon released Mr. Mattis’s resignation letter, in which he implicitly criticized his commander in chief. Mr. Mattis said in the letter that he believes that the president deserves a defense secretary who is more in tune with his worldview.
“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,” Mr. Mattis wrote.
“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,” he wrote.
His departure leaves the Trump administration without one of the few officials viewed as standing between a mercurial president and global tumult. The president said he would name Mr. Mattis’s replacement shortly.
The president’s tweets announcing the departure of his defense secretary shocked officials at the Pentagon, who as recently as Thursday afternoon were insisting that Mr. Mattis had no intention of resigning his post, despite his anger at Mr. Trump’s decision, announced on Wednesday, to withdraw American troops from Syria.
You’re Hired! You’re Fired! Yes, the Turnover at the Top of the Trump Administration Is … “Unprecedented.”
Since President Trump’s inauguration, White House staffers and cabinet officials have left in firings and resignations, one after the other.
Mr. Mattis had told close friends that he would continue in the job despite his deteriorating relationship with Mr. Trump, because he viewed his commitment to protecting the Defense Department and its 1.3 million active duty service members as paramount.
The widely accepted narrative that Mr. Mattis was the adult in the room when at the White House came to annoy Mr. Trump. In October, the president accused Mr. Mattis of being a Democrat — a charge akin to treason in the current Republican administration.
“This is scary,” Senator Mark Warner of Virginia, the top Democrat on the Senate Intelligence Committee, said in a tweet. He called Mr. Mattis “an island of stability amidst the chaos of the Trump administration.”
“As we’ve seen with the President’s haphazard approach to Syria, our national defense is too important to be subjected to the President’s erratic whims,” Mr. Warner wrote in the Twitter post.
Senator Marco Rubio, Republican of Florida and member of the Senate Foreign Relations Committee, said on Twitter that Mr. Mattis’s resignation letter “makes it abundantly clear that we are headed towards a series of grave policy errors which will endanger our nation, damage our alliances & empower our adversaries.”
As defense secretary, Mr. Mattis oversaw the world’s most powerful military, supervising active-duty troops based in the United States and deployed worldwide, including in war zones in Afghanistan, Iraq and on the Saudi border with Yemen. There are also around 25,000 American troops in South Korea, where they have served for generations as a deterrent against North Korea.
As with Mr. Trump’s abrupt firing of Jeff Sessions, the attorney general, the split with Mr. Mattis was a full turn in a relationship that once appeared strong.
In Mr. Mattis’s early days as defense secretary, he often ate dinner with Mr. Trump in the White House residence. Over hamburgers, and with the help of briefing folders, he explained to the president key points about America’s relationships with allies.
But Mr. Mattis also quietly slow-walked a number of Mr. Trump’s proposals, from banning transgender troops to starting a Space Force to putting on a costly military parade. In each case, he went through the motions of acquiescing to the White House — and then buried the plans in Defense Department red tape.
Over the past six months, the president and the defense chief have also found themselves at odds over NATO policy, whether to resume large-scale military exercises with South Korea and, privately, whether Mr. Trump’s decision to withdraw the United States from the Iran nuclear deal has proved effective.