Sir Kim Darroch resigned Wednesday as Britain’s ambassador to the US after incurring President Trump’s wrath for calling his administration “dysfunctional” and “inept” in a series of leaked diplomatic cables to London.

“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,” Darroch said in a letter to Simon McDonald, head of the Foreign Office.

“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,” he continued.

“Although my posting is not due to end until the end of this year, I believe in the current circumstances the responsible course is to allow the appointment of a new ambassador.”

On Monday, Trump tweeted that the US would “no longer deal” with Darroch following the leaked cache of cables to the UK’s Daily Mail.

The president continued lambasting Darroch the following day, describing him as “wacky” and a “pompous fool.”

“The wacky Ambassador that the U.K. foisted upon the United States is not someone we are thrilled with, a very stupid guy,” Trump said in a tweet.

The president also attacked British Prime Minister Theresa May, who had given Darroch her full support despite the diplomatic row.

On Wednesday, May told Parliament after the resignation was announced that she had spoken to Darroch. “I have told him it is a matter of great regret that he has felt it necessary to leave his position as ambassador to Washington,” she said.

“The whole Cabinet rightly gave its full support to Sir Kim,” who “has given a lifetime of service to the UK and we owe him an enormous debt of gratitude,” she added.

And in a veiled rebuke to Boris Johnson, who is vying to replace May as prime minister in two weeks, she added: “Good government depends on public servants being able to give full and frank advice.

“I hope the whole House will reflect on the importance of defending our values and principles, particularly when they are under pressure,” she said.

Foreign Secretary Jeremy Hunt — who also hopes to become prime minister — said in a statement that he was “deeply saddened” by Darroch’s decision to step down.

“For 42 years, Sir Kim served his country with the utmost dedication and distinction,” he said. “If one theme ran through all his endeavours, it was his unswerving devotion to upholding the interests of the United Kingdom, in the best tradition of British diplomacy.

“In that spirit, he brought dispassionate insight and directness to his reporting to ministers in London. Whenever I visited Washington as Foreign Secretary, I was struck by Sir Kim’s professionalism and intellect. I am outraged that a selection of his reports should have been leaked,” he continued.

“I am sure that our Ambassadors worldwide will continue to provide the objective and rigorous reporting that the Foreign and Commonwealth Office has always prized.”

On Tuesday, Hunt reprimanded Trump, tweeting that the president’s comments about Darroch were “disrespectful and wrong.”

Johnson has said that whoever leaked the diplomatic cables should be “eviscerated.”

“I think it’s very important we should have a close partnership, a close friendship with the United States,” he said.

On Wednesday, Labour leader Jeremy Corbyn also paid tribute to Darroch, saying “the whole House should come together in deeply regretting” the fact he felt the need to quit, the Mirror reported.

In one leaked memo from 2017, Darroch 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.”

He also questioned whether the White House “will ever look competent.”

In his resignation letter, Darroch wrote: “I am grateful to all those in the UK and the US, who have offered their support during this difficult few days. This has brought home to me the depth of friendship and close ties between our two countries. I have been deeply touched.

“I am also grateful to all those with whom I have worked over the last four decades, particularly my team here in the US. The professionalism and integrity of the British civil service is the envy of the world. I will leave it full of confidence that its values remain in safe hands.”

Trump has not reacted yet to the resignation.