Sir Kim Darroch has resigned as UK ambassador to the US, amid a row over leaked emails critical of President Trump's administration.
The ambassador was branded "a very stupid guy" by Donald Trump, after emails emerged calling his administration "clumsy and inept".
The Foreign Office praised Sir Kim's "professionalism and class".
The ambassador said he wanted to put an end to speculation, adding the leak had made it "impossible" to do his job.
In a letter to the Foreign Office, Sir Kim said: "Since the leak of official documents from this Embassy there has been a great deal of speculation surrounding my position and the duration of my remaining term as ambassador."
"I want to put an end to that speculation."
"The current situation is making it impossible for me to carry out my role as I would like."
In response to his letter of resignation, Sir Simon McDonald, permanent under secretary and head of the diplomatic service, said Sir Kim had served a "long and distinguished career, with dignity, professionalism and class".
Theresa May said it was a "matter of great regret" that Mr Darroch felt the need to resign, saying officials needed to be able to give "full and frank advice".
The prime minister said he had had the full support of the Cabinet during the row.
Labour leader Jeremy Corbyn told the Commons: "The comments made about him are beyond unfair and wrong. I think he has given honourable and good service and he should be thanked for it."
Sir Kim had been due to step down at the end of the year.
He thanked those who had offered their support, both in the UK and the US, during a "difficult few days", adding that it had "brought home to me the depth of friendship and close ties between our two countries".
Who is Sir Kim Darroch?
Born in South Stanley, County Durham, in 1954, Sir Kim attended Durham University where he read zoology.
During a 42-year diplomatic career, he has specialised in national security issues and European Union policy.
In 2007, Sir Kim served in Brussels as the UK permanent representative to the EU.
He was the prime minister's national security adviser between 2012 and 2015, dealing with issues such as the rise of the Islamic State group in Iraq and Syria, Russian annexation of Crimea, the nuclear threat from Iran and the collapse of government authority in Libya.
He became ambassador to the US in January 2016, a year before Donald Trump's presidential inauguration.