The U.S. ambassador to Estonia has resigned over frustrations with President Trump's comments about the European Union and his treatment of Washington's European allies.

In a private Facebook message posted Friday, James D. Melville wrote: "For the President to say 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 was referring to Mr. Trump's recent comments at news conferences and on social media.

Get Breaking News Delivered to Your Inbox

Melville stressed that a U.S. foreign service officer's "DNA is programmed to support policy and we're schooled right from the start, that if there ever comes a point where one can no longer do so, particularly if one is in a position of leadership, the honorable course is to resign."

Melville is a senior U.S. career diplomat who has served as the American ambassador in the Baltic nation and NATO member of Estonia since 2015. He has served at U.S. Embassies in Berlin, London and Moscow, among other postings.

"Having served under six presidents and 11 secretaries of state, I never really thought it would reach that point for me," he wrote, referring to a career with the State Department that started in the mid-1980s.

The U.S. Embassy in Tallinn confirmed to The Associated Press on Saturday that Melville "announced his intent to retire from the Foreign Service effective July 29 after 33 years of public service." It did not elaborate.