The US ambassador to Panama has resigned from his post on principle, writing in a resignation letter to the State Department that he can no longer serve the Trump administration.

The US State Department confirmed the departure of John D Feeley, saying he decided to “retire for personal reasons, as of 9 March this year”.

Mr Feeley wrote in his resignation letter: “As a junior foreign service officer, I signed an oath to serve faithfully the President and his administration in an apolitical fashion, even when I might not agree with certain policies.

“My instructors made clear that if I believed I could not do that, I would be honour-bound to resign. That time has come.”

The State Department learned of his plans on 27 December, Reuters reported – well before the Washington Post reported Donald Trump had referred to “s***hole countries” in a meeting about immigration.

Haiti, El Salvador and unspecified African nations were said to have been among those discussed with the President at a briefing with congressional leaders.

Mr Trump has denied he used that language but admitted speaking in a “tough” manner during the Oval Office meeting on immigration reform and the Deferred Action for Childhood Arrivals (DACA) programme.

Mr Feeley was one of the State Department’s Latin America specialists and among its most senior officers.

According to a Spanish copy of the notice of Mr Feeley’s resignation, tweeted by Univision News, the Barack Obama appointee has been in public service for 35 years, in the US Marine Corps and State Department.

The notice said he held an “unbreakable” belief in the need for close ties between American countries.

Under-secretary of State Steve Goldstein said Mr Feeley’s departure was not a response to the President’s reported comments.

“Everyone has a line that they will not cross,” he said. “If the ambassador feels that he can no longer serve … then he has made the right decision for himself and we respect that.”

The Trump administration has taken a tougher stance on immigration from Latin America, most notably with moves to expel hundreds of thousands of immigrants from El Salvador, Haiti and Nicaragua who benefited from temporary protection status after natural disasters.

Mr Trump’s alleged “s***hole” comments on Thursday led to outraged responses from Haiti and the African Union. The AU said it was “alarmed” by the nature of the President’s remarks while Haiti’s government criticised “these insulting and reprehensible statements”.

El Salvador’s foreign minister said he had sent a formal letter of protest in response to the reports.

On Twitter, Mr Trump twice denied having used the word “s***hole”.

But Democratic senator Dick Durbin, who was present at the DACA meeting, claimed he had used it “repeatedly”.