Sir Kim Darroch has resigned as UK ambassador to the US, as a row over leaked emails critical of President Trump's administration escalates.
Theresa May said Sir Kim's departure was "a matter of deep regret" after the ambassador said it was "impossible" for him to continue.
Tory leadership candidate Boris Johnson has faced strong criticism for failing to fully support him.
President Trump said on Monday that the US would not deal with Sir Kim.
The US president had branded him "a very stupid guy" after confidential emails emerged where the ambassador had called his administration "clumsy and inept".
In a letter to the Foreign Office, Sir Kim said he wanted to end speculation about his position: "The current situation is making it impossible for me to carry out my role as I would like."
His resignation has prompted widespread support for Sir Kim as well as criticism of Tory frontrunner Boris Johnson.
According to some Whitehall sources, Sir Kim decided to resign after Mr Johnson refused to support him during the Tory leadership debate on Tuesday night, said BBC diplomatic correspondent James Landale.
Mr Johnson was asked repeatedly by fellow leadership candidate Jeremy Hunt whether he would keep Sir Kim in post if he became prime minister, but refused to answer.
It is understood Mr Johnson spoke to Sir Kim on the phone on Wednesday afternoon.
Sources close to Mr Johnson said that he praised Sir Kim's dedication and hard work and claimed the conversation was warm and cordial.
Following Sir Kim's resignation, Mr Johnson said he was "a superb diplomat" and whoever was responsible for the leak "has done a grave disservice to our civil servants".
Asked why he was not more supportive of Sir Kim, he said it was "wrong to drag civil servants into the political arena".
Europe Minister Sir Alan Duncan - who backs Mr Hunt in the leadership contest - said it was "contemptible negligence" of Mr Johnson not to support Sir Kim.
"He's basically thrown this fantastic diplomat under a bus to serve his own personal interests," he said.
However, Sir Michael Fallon - a supporter of Mr Johnson - told BBC Newsnight Sir Kim's position became untenable "long before the debate on Tuesday night" and he understands the ambassador did not watch it.
The backlash against Mr Johnson was "a shabby attempt to politicise" the affair and the leadership contender had "made it clear he supports all our diplomats", he said.
Labour leader Jeremy Corbyn said Mr Johnson wanted a "sweetheart trade deal" with the US and his lack of support for Sir Kim "shows he won't stand up to Donald Trump".
Tory MP and chairman of the Commons' foreign affairs committee Tom Tugendhat said in a tweet: "Leaders stand up for their men. They encourage them to try and defend them when they fail."
Fellow Tory leadership candidate and Foreign Secretary Mr Hunt told the BBC Sir Kim was "doing his job" and his resignation was "a black day for British diplomacy".
Mrs May said Sir Kim had had the full backing of the cabinet and he was owed an "enormous debt of gratitude" for his "lifetime of service" to the UK.
Public servants should be able to give "full and frank advice", she added.
by James Landale, BBC diplomatic correspondent
So was it Boris Johnson what done it? Was the failure of the former foreign secretary to defend Sir Kim in last night's Tory leadership debate the crucial factor in the ambassador's decision to resign?
Without Sir Kim speaking publicly on the subject, we are reliant on others to speak for him.
And certainly, according to well-placed sources in Whitehall, Mr Johnson's decision to avoid criticising President Trump and his lack of support for Sir Kim was said to be the straw that broke the camel's back.
If you are an embattled diplomat under fire from your host country, you need cover from London. And if that is lacking from the man tipped to be your next boss, you realise the writing is on the wall.
Certainly, there is genuine anger across Westminster and Whitehall at Mr Johnson's refusal six times last night to come to the aid of our man in Washington.
Mr Johnson's supporters have offered varying counter theories. Some have accused Mr Hunt's supporters of politicising the resignation.
Others have insisted that the decision had been made before the debate, once Mr Trump declared he would no longer deal with Sir Kim.
Realising they were on the receiving end of potentially damaging criticism, Mr Johnson's aides also let it be known that he called Sir Kim this afternoon and praised his dedication and hard work.
The problem is that few in Westminster were giving much credence to these defences.
In the House of Commons, Theresa May pointedly urged MPs to "reflect on the importance of defending our values and principles, particularly when they are under pressure".
It was not hard to decipher what she was talking about.
Head of the diplomatic service Sir Simon McDonald said it was the first time in his career that a head of state had refused to work with a British ambassador.
He described the leak as "malicious" and told Sir Kim: "You are the best of us."
Republican Senator Lindsey Graham - a supporter of President Trump - said Sir Kim had done "an outstanding job" as ambassador and his resignation was "a chilling moment".
"Ambassadors need to be able to talk to their governments without fear of being compromised," he said.
In a letter to Sir Kim, Cabinet Secretary and civil service head Sir Mark Sedwill said that while he understood his reasons for resigning it was "a matter of enormous regret that you were put in this position after a shocking betrayal of trust".
Cabinet Office Minister David Lidington said he was "enraged" by the situation and morale in the senior ranks of the civil service had taken "a very heavy blow".
Former head of the civil service Lord O'Donnell told the BBC Sir Kim's successor could be chosen within two weeks - while Mrs May is still prime minister.
President Trump could well wake up this morning thinking he has the power to veto who the UK has as its ambassador.
It wasn't his more colourful remarks on Twitter that really ended Sir Kim's time, but Mr Trump's public announcement that he would no longer work with him.
The effects of that were felt immediately. There was a banquet that Sir Kim was immediately dis-invited from. Next, he couldn't attend an event with minister Liam Fox.
It was clear he was being frozen out and for an ambassador access is everything. Without it, it's impossible to do the job.
More broadly, it's like this... There's never been parity in the special relationship between the UK and US - it's never been a relationship of equals but right now it seems particularly lopsided.
The US knows that Britain is fairly isolated right now internationally and needs the US more than ever. Donald Trump has wielded that power mercilessly in this row.
In the emails leaked to the Mail on Sunday, Sir Kim said: "We don't really believe this administration is going to become substantially more normal; less dysfunctional; less unpredictable; less faction-riven; less diplomatically clumsy and inept."
The emails, dating from 2017, said rumours of "infighting and chaos" in the White House were mostly true.
The government has opened an internal inquiry into the publication of the memos and police have been urged to open a criminal investigation.
Downing Street confirmed there had been some "initial discussions" with police regarding the leak and if there was concern about criminal activity they would become involved "more formally".
Metropolitan Police Commissioner Cressida Dick said it was "deeply worrying" diplomatic cables had ended up in the public domain.