WASHINGTON — Defense Secretary James Mattis will step down at the end of February, telling President Donald Trump in a letter Thursday that he has "a right to have a Secretary of Defense whose views are better aligned with yours."

In his extraordinary letter to Trump, Mattis said that a long-held "core belief" of his "is that our strength as a nation is inextricably linked to the strength of our unique and comprehensive system of alliances and partnerships."

Without maintaining those alliances, he wrote, "we cannot protect our interests or serve" the role of an "indispensable nation in the free world."

The president has frequently lashed out at America's allies in France, the United Kingdom, Canada and Germany, while at times appearing to side with U.S. adversaries over his own officials.

"My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors," Mattis said, "are strongly held and informed by over four decades of immersion in these issues."

Read Mattis' full resignation letter here.

Mattis' resignation letter, which a Pentagon spokeswoman said was hand-delivered to the president Thursday afternoon, comes on the heels of Trump's controversial plan to withdraw U.S. troops from Syria.

That announcement on Wednesday will reportedly take more than 2,000 U.S. service members out of the country, ending the ground strategy against the Islamic State. Trump said in a tweet Wednesday morning that "we have defeated ISIS in Syria, my only reason for being there during the Trump Presidency."

The move was met with heated criticism from a number of Trump's usual allies in Congress. But Russian President Vladimir Putin said that Trump made the "correct" move, because the U.S. troops had no legal right to be in Syria.

On Thursday evening, defense officials told NBC News that the White House has ordered the Pentagon to look into plans for withdrawing troops from Afghanistan, as well.

Trump had announced that Mattis "will be retiring, with distinction," in a pair of tweets Thursday. A new defense secretary "will be named shortly," Trump said.

Trump tweet 2

A senior administration official told CNBC that Mattis told Trump he was resigning during a meeting Thursday. "He and the president had differences on some issues," the official said.