LONDON — The British ambassador to Washington has resigned following a leak of diplomatic cables in which he described President Donald Trump and his administration as “inept” and “chaotic,” Britain’s Foreign Office said Wednesday.

Kim Darroch, who had been the target of days of angry attacks from Trump, wrote that he had decided to quit because “in the current circumstances the responsible course is to allow the appointment of a new ambassador.”

Prime Minister Theresa May, who had stood by the 65-year-old envoy and said he was only doing his job when he provided blunt assessments of the Trump administration, said his decision to step down was a “matter of great regret.”

Addressing lawmakers, May — who is herself set to step down within weeks — said it was “essential” for professional diplomats like Darroch to be able to be candid in their reports to their home governments.

The leaked cables appeared the British tabloid the Mail on Sunday. Covering a span from 2017 to the recent past, the diplomatic memos, which were supposed to have been confidential, depicted Trump as erratic, unpredictable and seemingly immune to scandal. His White House was portrayed as a nest of infighting.

In his resignation letter, Darroch said he was “grateful to all those” in Britain and the United States who had offered support “during this difficult few days.”

The ambassador’s decision came hours after a televised debate in which Boris Johnson, the front-runner to become the next prime minister, refused to defend the ambassador or criticize Trump.

In a series of tweets on Tuesday, Trump called the veteran envoy “wacky” and a “very stupid guy.”

Perhaps more crucially, Trump also said earlier this week that “we” would no longer deal with Darroch, without specifying exactly what that meant. The State Department said Tuesday it had received no instructions from the White House to cut ties with the British embassy, but in the wake of the leak, the ambassador was disinvited from at least two official events.

In practical terms, any senior diplomat is highly dependent on access. Darroch had previously had cordial ties with senior members of the Trump administration, and a cutoff of such contacts would impede his ability to gather information and also to advance his own country’s interests.

In a strongly worded response to Darroch’s letter, the Foreign Office accepted his decision to quit but emphasized that he had done nothing wrong. The head of the diplomatic service, Simon McDonald, said the ambassador had been undermined by a “malicious” leak.

Praising Darroch for a “long and distinguished career,” McDonald wrote: “You are the best of us.”

Johnson’s rival for the prime minister’s post, Foreign Secretary Jeremy Hunt, tweeted that he was “deeply saddened” by the ambassador’s resignation.

“Standing up for Britain means standing up for the finest diplomats in the world,” Hunt wrote. “It should never have come to this.”

Johnson, for his part, said that whoever was behind the leak “really has done a grave disservice to our civil servants.” Employing typically colorful language, he added: “I hope that whoever it is, is run down, caught and eviscerated.”

But Johnson’s failure to stand up for Darroch was already drawing some heavy fire from within his Conservative Party.

Los Angeles Times