The US envoy to forces fighting to defeat Islamic State has resigned over Donald Trump’s decision to withdraw troops from Syria.

Brett McGurk’s resignation follows that of Trump’s defense secretary, James Mattis, who announced his departure this week.

As special presidential envoy for the global coalition to defeat Isis since 2015, McGurk was one of few Obama appointees to stay on under Trump. He is also a former supreme court clerk and served Obama and George W Bush as a diplomat, focusing on Iran and Iraq.

CBS News first reported McGurk’s move. Citing anonymous sources, it said he had planned to leave in February but had brought the move forward due to a “strong disagreement” with the president. He will quit at the end of this month and take up a post in academia.

The New York Times obtained an email sent by McGurk, 45, to his staff.

The recent decision by the president came as a shock and was a complete reversal of policy Brett McGurk

“The recent decision by the president came as a shock and was a complete reversal of policy that was articulated to us,” McGurk wrote, according to the paper. “It left our coalition partners confused and our fighting partners bewildered.”

Mattis resigned on Thursday, issuing a letter of resignation that was implicitly strongly critical of Trump for his neglect of allies, reportedly angering the president. It was widely reported that the defense secretary quit after Trump made the decision to withdraw from Syria during a conversation with the Turkish president, Recep Tayyip Erdoğan.

CBS said McGurk was in the region for talks with America’s Kurdish allies when Trump announced his decision. The Kurds fear attack by Turkey if around 2,000 US troops stationed in Syria are withdrawn.

In the email quoted by the Times, McGurk wrote: “I worked this week to help manage some of the fallout but – as many of you heard in my meetings and phone calls – I ultimately concluded that I could not carry out these new instructions and maintain my integrity.”

On 11 December, McGurk told reporters at the state department he thought it was “fair to say Americans will remain on the ground after the physical defeat of the caliphate, until we have the pieces in place to ensure that that defeat is enduring”.

He also said it would be “reckless” to consider Isis to have been defeated, a claim repeatedly made by Trump.

Brett McGurk (left) in northern Syria. Photograph: Delil Souleiman/AFP/Getty Images

On Twitter on Saturday shortly after McGurk’s resignation was reported, Trump defended his decision to withdraw, writing that US troops had meant to be in Syria “for three months, and that was seven years ago – we never left”.

The claim was inaccurate. The Syrian civil war began seven years ago, in 2011, but US airstrikes there began in September 2014 and troops were not sent until the following year.

In words that will likely be greeted with dismay among Kurdish forces, the president added: “When I became president, Isis was going wild. Now Isis is largely defeated and other local countries, including Turkey, should be able to easily take care of whatever remains. We’re coming home!”

Later, Trump directly addressed McGurk’s resignation, claiming “I do not know” the adviser, and asking: “Grandstander? The Fake News is making such a big deal about this nothing event!”

He was more circumspect about Mattis, whom he has frequently lionised.

“When President Obama ingloriously fired Jim Mattis, I gave him a second chance,” Trump wrote. “Some thought I shouldn’t, I thought I should. Interesting relationship – but I also gave all of the resources that he never really had.”

He added, in reference to Mattis’s criticisms of the president’s dismissive attitude towards longstanding US allies: “Allies are very important-but not when they take advantage of US.”

Outside the administration, McGurk was widely praised. The Obama national security adviser and United Nations ambassador Susan Rice saluted his “exceptional, selfless, non-partisan service”. The former Obama adviser Ben Rhodes said: “We all owe him our gratitude – he literally made us safer.”

The Washington Post reporter Jason Rezaian, whose release from captivity in Iran in 2016 McGurk helped secure, wrote: “As an American citizen directly impacted by [McGurk’s] work as a diplomat, I thank him deeply for his years of dedicated service. Without his relentless efforts [Yeganeh Rezaian, his wife who was also held] and I would not be here. That’s a fact.”

Others combined praise with criticism of Trump. John Brennan, the former Obama homeland security adviser and CIA director who is a harsh critic of the president, tweeted: “Brett worked extremely hard over many years to ensure the US fulfilled its leadership role in a critically important part of the world. Like Sec[retary] Mattis, Brett believes in the principles, values [and] partnerships that define America. Donald Trump does not.”

The Associated Press reported that an anonymous US official said McGurk had been pushing for Kurdish fighters to be allowed to seek protection from troops allied with the Syrian president, Bashar al-Assad.

The envoy, the report said, argued that the US “had a moral obligation to help prevent the allied fighters from being slaughtered by Turkey”.