WASHINGTON — Less than two hours after Defense Secretary Jim Mattis went to the White House on Thursday to hand a resignation letter to President Trump, the president stood in the Oval Office and dictated a glowing tweet announcing that Mr. Mattis was retiring “with distinction” at the end of February.
But Mr. Trump had not read the letter. As became apparent to the president only after days of news coverage, a senior administration official said, Mr. Mattis had issued a stinging rebuke of Mr. Trump over his neglect of allies and tolerance of authoritarians. The president grew increasingly angry as he watched a parade of defense analysts go on television to extol Mr. Mattis’s bravery, another aide said, until he decided on Sunday that he had had enough.
In a tweet later that morning, the president announced that he was removing Mr. Mattis from his post by Jan. 1, two months before the defense secretary had planned to depart. Mr. Trump said that Patrick M. Shanahan, Mr. Mattis’s deputy and a former Boeing executive, would serve as the acting defense secretary, praising him as “very talented” and adding that “he will be great!”
Mr. Trump’s sudden announcement that he was firing a man who had already quit was the exclamation point to a tumultuous week at the Pentagon, where officials have been reeling from day after day of presidential tweets announcing changes in American military policy.
Mr. Mattis had wanted to stay through a NATO defense ministers meeting scheduled for February, hoping to enshrine recent moves by the alliance to bulk up its security compact as a bulwark against Russia. But Mr. Mattis’s resignation letter did him no favors on that count: It had become hard to envision how he could continue for two months to represent a president whose own views toward Russia are far more benign.
As it became clear that the two men’s ideas of how to treat both friends and adversaries were so publicly at odds, the White House decided that there would be no reason for Mr. Mattis to stay on during what two officials called his “lame duck” period.
Officials in allied nations, who had already expressed unease over Mr. Mattis’s resignation, voiced exasperation over his hastened departure. “And now Trump gets rid of SecDef Mattis almost immediately,” Carl Bildt, a former prime minister of Sweden, wrote on Twitter. “No smooth transition. No effort at reassurance to allies. Just vindictive.”
Even as he accelerated Mr. Mattis’s exit, Mr. Trump seemed to suggest a slower one for the 2,000 troops in Syria — a drawdown he announced last week over Mr. Mattis’s objection. On Twitter, Mr. Trump said that he had spoken with President Recep Tayyip Erdogan of Turkey that morning to discuss “the slow and highly coordinated pullout of U.S. troops from the area.”
Just days ago, Mr. Trump declared victory over the Islamic State and said that troops would be pulled out immediately. “They’re all coming back,” Mr. Trump said in a video broadcast on Wednesday, “and they’re coming back now.”
On Sunday, a senior administration official would not say what that ultimately meant for the timetable for troops in Syria, but said the president had reiterated to Mr. Erdogan that the United States would remain there long enough to ensure an orderly handover and “help out logistically” to eradicate any territory still held by the Islamic State.
The official spoke amid reports that Turkey was moving troops near a town in northern Syria held by Kurdish allies of the United States, even though Turkey had said it would put off a promised offensive after Mr. Trump’s hasty decision to leave Syria.
Mr. Mattis resigned on Thursday in large part over that pullout order. The defense secretary was also upset about Mr. Trump’s decision to bring home half of the 14,000 American troops stationed in Afghanistan and his order to deploy American troops to the border with Mexico.
The president has grown increasingly angry as commentators have described Mr. Mattis in near heroic terms for standing up to Mr. Trump and making his resignation count as no one else in the president’s circle has done, an aide said. On Saturday, Mr. Trump took a jab at Mr. Mattis on Twitter, saying that “when President Obama ingloriously fired Jim Mattis, I gave him a second chance. Some thought I shouldn’t, I thought I should.”
Mr. Mattis, a retired four-star general, led the United States Central Command, which oversees military operations in the Middle East and Southwest Asia, from 2010 to 2013. His tour there was cut short by the Obama administration, which believed he was too hawkish on Iran.
By Sunday morning, Mike Pompeo, the secretary of state, had informed Mr. Mattis that he would have just over another week in his current job. Mr. Pompeo and John R. Bolton, the president’s third national security adviser since taking office, are left to direct policy while the president considers an official replacement for Mr. Mattis. In a call with reporters, a White House official framed Mr. Shanahan’s tenure as one that could keep daily operations stable in the interim.
Brett H. McGurk, the special presidential envoy to the coalition fighting the Islamic State, is also stepping down over Mr. Trump’s decision to pull troops from Syria, telling colleagues this weekend that he could not in good conscience carry out Mr. Trump’s new policy.
Mr. McGurk, a seasoned diplomat who was considered by many to be the glue holding together the sprawling international coalition fighting the terrorist group, was supposed to retire in February. But according to an email he sent to his staff, he decided to move his departure forward to Dec. 31 after Mr. Trump did not heed his own commanders and blindsided America’s allies in the region by abruptly ordering the pullout.
Mr. Shanahan, who, like Mr. Mattis, is from Washington State, was at Boeing for 30 years, in a number of jobs including general manager of the 787 Dreamliner and senior vice president of supply chain and operations. Aides say that Mr. Trump likes him in part because he often tells the president that he is correct to complain about the expense of defense systems.
“Patrick has a long list of accomplishments while serving as Deputy, & previously Boeing,” Mr. Trump tweeted.
At the Defense Department last year, Mr. Shanahan scuttled a pledge to destroy the military’s existing stockpile of cluster munitions, allowing the military to once again arm itself with a type of weapon that has been banned by 102 countries largely because of concerns that the arms disproportionately harm civilians.
Asked about the decision at a conference in October, Mr. Shanahan attributed the move to what he said was the threat posed by North Korea.
On Sunday, in N’Djamena, Chad, President Emmanuel Macron of France criticized Mr. Trump’s decision to withdraw American forces from Syria, saying that “an ally must be reliable.” French forces are part of a coalition led by the United States aimed at destroying the Islamic State, but it is unclear what will happen to the coalition now.
Mr. Macron also praised Mr. Mattis, seeming to contrast him to Mr. Trump. “I want here to pay tribute to General Mattis,” Mr. Macron said. “For a year we have seen how he was a reliable partner.”