Part of Defense Secretary Jim Mattis' resignation letter to President Donald Trump is photographed in Washington, Thursday, Dec. 20, 2018. Mattis is stepping down from his post, Trump announced, after the retired Marine general clashed with the president over a troop drawdown in Syria and Trump's go-it-alone stance in world affairs. (AP Photo/Jon Elswick)
Part of Defense Secretary Jim Mattis' resignation letter to President Donald Trump is photographed in Washington, Thursday, Dec. 20, 2018. Mattis is stepping down from his post, Trump announced, after the retired Marine general clashed with the president over a troop drawdown in Syria and Trump's go-it-alone stance in world affairs. (AP Photo/Jon Elswick) Credit: Jon Elswick

Washington — Defense Secretary Jim Mattis resigned on Thursday after a clash with President Donald Trump over the withdrawal of U.S. troops from Syria, saying in a parting letter that the president deserved someone atop the Pentagon who is “better aligned” with his views.

The retired Marine general’s surprise resignation came a day after Trump overruled his advisers, including Mattis, and shocked American allies by announcing the pullout. In the process, Trump declared victory over the Islamic State, even though the Pentagon and State Department for months have been saying the fight against the group in Syria is not over.

The discord caused Trump to lose a Cabinet official who won widespread praise at home and abroad but who experienced increasing differences with the commander in chief.

Long seen as a bulwark against Trump’s isolationist and more extreme impulses, Mattis served as a calm “reassurer-in-chief” as the president sent out startling and provocative tweets. Mattis’ departure adds new uncertainty about which course the administration might take on its global challenges.

Mattis pointed to some of his differences with Trump in a resignation letter he submitted to the White House on Thursday. The retired general emphasized that the United States derives its strength from its relationships with allies and should treat them with respect. He said the country must also be “clear-eyed” about threats, including from groups such as the Islamic State.

“We must do everything possible to advance an international order that is most conducive to our security, prosperity and values, and we are strengthened in this effort by the solidarity of our alliances,” Mattis wrote.

The defense secretary resigned during what one senior administration official described as a disagreement in the Oval Office on Thursday afternoon, in which Mattis sought to persuade the president to stand down on the Syria withdrawal but was rejected. Trump was later given a copy of the resignation letter and noted to aides that it was not positive toward him. By then, the president had shocked the Pentagon by filming a video on the White House lawn in which he claimed the Islamic State had been defeated and said U.S. troops who had died in combat would be proud to see their fellow service members return home.

While the Syria announcement looked poised to score political points with the public, Mattis and other top advisers suspect that it will deliver a win to Russia, Iran and Syrian leader Bashar Assad, while risking a resurgence of the Islamic State.

Mattis also has argued against drawing down troops from Afghanistan, which Trump is leaning toward executing in the coming months, according to administration officials. Senior administration officials said late Thursday that Trump had ordered the military to come up with a plan to remove thousands of troops from the country, after a 17-year war, starting as early as January. The United States has about 14,000 troops deployed to Afghanistan as part of a NATO mission.

The Pentagon released the resignation letter moments after Trump announced on Twitter that Mattis would be leaving, saying the already retired Marine would “retire.” Trump made no mention of his differences in opinion with Mattis.

“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,” Trump tweeted. “During Jim’s tenure, tremendous progress has been made, especially with respect to the purchase of new fighting equipment. 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!”

During his nearly two years at the Pentagon, Mattis secured sizable increases in defense spending after years of budget caps and oversaw the development of a new strategy that orients the military toward competition with China and Russia and away from combating extremist insurgencies in the Middle East.

A staunch Russia hawk, Mattis bristled at the president’s conciliatory gestures toward Russian President Vladimir Putin and moves to undermine NATO, according to people close to him. Russia and China “want to shape a world consistent with their authoritarian model,” Mattis underscored in his resignation letter.

Moscow and Beijing were looking for “veto authority over other nations’ economic, diplomatic and security decisions,” he said, warning the president that the United States must “use all the tools of American power to provide for the common defense.”

Lawmakers, ambassadors and policymakers for two years have looked to Mattis as a source of stability in a chaotic administration. His sudden resignation on Thursday sent jitters through a Washington establishment already coping with a meltdown in the financial markets and a possible government shutdown.

House Minority Leader Nancy Pelosi, D-Calif., said she was “shaken” by the resignation and described it as “very serious for our country.”

Sen. Maggie Hassan, D-N.H., released a statement saying, “Secretary Mattis’s resignation letter powerfully raises concerns from members of both parties about the President’s haphazard, impulsive approach to security issues, his failure to strategically confront our adversaries, his contempt for our allies, and his desire to abandon America’s vital role in maintaining an international order that protects our security and our values. Members of both parties must step up now to do everything we can to promote a coherent American foreign policy that will keep us safe, secure, and free.”

Republicans were also dismayed by the decision.

Sen. Ben Sasse, R-Neb., said it was “a sad day for America because Secretary Mattis was giving advice the president needs to hear.” Sasse said Mattis “rightly believes” that Russia and China are adversaries and described the isolationism that Trump sometimes promotes as a “weak strategy that will harm Americans and America’s allies.” Sasse added: “No, ISIS is not gone.”

Known as the “Warrior Monk” from his days in uniform, Mattis developed a reputation as a cerebral thinker in the Marine Corps who liked to deliberate, read and study all possibilities before making important decisions.

That style clashed with the most freewheeling presidential administration in the postwar era, most notably this week, when Trump decided to withdraw from Syria without first running the move through a regular policy process that would consider the options and ramifications.