Ambassador James D. Melville announced in a message to friends on social media late on Friday evening that he has decided to resign. Recent statements by U.S. President Donald Trump that the EU was "set up to take advantage of the United States" and that "NATO is as bad as NAFTA" are not only factually wrong, but prove that it is time for him to go, Melville wrote.

Melville, whose career in the U.S. Foreign Service spans 33 years, has been ambassador to Estonia since 2015. Melville served under six presidents and 11 secretaries of state. According to Foreign Policy, his decision to resign came as a surprise to State Department officials who worked with him.

The State Department confirmed Melville's departure, effective 29 July. According to CNN, Melville is the third career diplomat in the last year to leave the State Department early.

In his letter, Ambassador Melville wrote that a foreign service officer's DNA is programmed to support policy, and that at the point where they no longer can, the honourable thing to do is to resign.

"For the President to say the EU was 'set up to take advantage of the United States, to attack our piggy bank,' or that 'NATO is as bad as NAFTA' is not only factually wrong, but proves to me that it's time to go," Melville wrote, citing Trump's reported comments in recent weeks that have unnerved U.S. allies.

"I leave willingly and with deep gratitude for being able to serve my nation with integrity for many years, and with great confidence that America, which is and has always been, great, will someday return to being right," Melville added.

Foreign Policy magazine pointed out that the resignation comes ahead of a pivotal NATO summit, where the United States' closest historic allies fear that Trump will lambast them and further isolate Washington from its allies after heated disputes over trade, defense spending issues, and the U.S. exit from the Iran nuclear deal. Allies fear that the optics of Trump trashing allies in Brussels, followed by a meeting in Finland with Russian President Vladimir Putin, will undercut an already anemic trans-Atlantic partnership.

In a statement, a State Department spokesperson confirmed Melville's departure. "Earlier today, the United States' Ambassador to Estonia, Jim Melville, announced his intent to retire from the Foreign Service effective 29 July after 33 years of public service," the statement read.