After several days of intense criticism by President Trump, who called the British ambassador to Washington a “pompous fool” and said his administration would no longer work with him, Kim Darroch on Wednesday resigned his post.

Darroch provoked the president’s ire when a cache of secret diplomatic cables were leaked to a British tabloid over the weekend. The memos from Darroch described Trump as “insecure” and his administration as “inept” and “dysfunctional.”

Prime Minister Theresa May stood by Darroch — and she told Parliament on Wednesday it was a “matter of great regret that he has felt it necessary to leave his position.”

“Sir Kim has given a lifetime of service to the United Kingdom, and we owe him an enormous debt of gratitude,” she said in Parliament.

“Good government depends on public servants being able to give full and frank advice,” she said, adding, “I hope the House will reflect on the importance of defending our values and principles, particularly when they are under pressure.”

In his resignation letter, Darroch wrote, “The current situation is making it impossible for me to carry out my role as I would like.” He noted that his posting would have been up at the end of the year but that he had decided to depart now.

The controversy over the cables marked the latest uncomfortable moment of tension between the United States and Britain during the Trump administration — with most focused on the president’s on-again, off-again criticism of May’s handling of Brexit.

Attention will soon turn to how the new prime minister manages the relationship with Trump. Boris Johnson, the former mayor of London and former foreign secretary, is the odds-on favorite to win the race for leadership of the Conservative Party and succeed May as prime minister toward the end of the month. He is a Trump favorite because of his pro-Brexit stance, but handling the U.S. president has been a challenge for leaders across Europe, where he continues to be unpopular.

Darroch told staffers Tuesday he could not be an effective ambassador if the administration would not deal with him — and the episode did not seem to be passing. But also key to his decision, a person familiar with his thinking said, was the clear lack of support from Johnson.

During a televised debate Tuesday evening, Johnson declined to criticize Trump for his tweets insulting Darroch and May and would not promise to keep Darroch on the job.

Johnson’s opponent, Foreign Secretary Jeremy Hunt, said he backed Darroch. After the ambassador’s resignation, Hunt said he was “deeply saddened.”

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

White House officials suggested Darroch’s departure was appropriate.

“I think the reality was that, in light of the last few days, his ability to be effective was probably limited,” Vice President Pence’s chief of staff, Marc Short, told reporters in Washington on Wednesday. “So it was probably the right course.”

Trump claimed that Darroch was “not liked or well thought of within the U.S.” But senior political figures in Washington expressed disappointment at the ambassador’s departure.

Sen. Mark R. Warner (D-Va.), vice chairman of the Senate Intelligence Committee, wrote: “@KimDarroch was an outstanding Ambassador who served his country with honesty and integrity. He was a true friend to the United States, and it’s a shame to see him go.”

In Britain on Wednesday, much of the anger focused on Johnson, who was accused of giving the impression that he was more willing to appease the American president than stick up for a career civil servant.

“Boris Johnson isn’t even PM yet and he is already responsible for a grievous blow to the UK’s international reputation,” tweeted Nick Boles, an independent lawmaker and onetime Johnson adviser, adding, “The British people can now see that Boris Johnson will be Donald Trump’s poodle, that his response to any command from the White House will be: ‘How high, Mr President?’ ”

Alan Duncan, a Foreign Office minister, told the BBC that Johnson had “basically thrown our top diplomat under the bus, and there are a lot of people here in the Commons who are very, very angry.”

Tom Tugendhat, chair of the Foreign Affairs Committee, told Sky News: “If we allow ourselves to be bullied in who we chose to represent us, then frankly, what does sovereignty mean? If you can’t even choose who represents you, then in what way are you in charge of anything?”

The Daily Mirror went with the front-page headline “Traitor Boris backs Trump not Britain.”

On Wednesday, Johnson shifted slightly, saying Darroch was a “a superb diplomat” who he worked with for “many years.” Johnson said that whoever leaked the cables should be “run down, caught and eviscerated.”

The British Foreign Office earlier this week announced a probe to find the source of the leak but has reported no progress. The cables — known as “diptels” — had limited circulation, but diplomats said that they began circulating as far back as 2017 and that finding the culprit may prove difficult.

One British government official with knowledge of the incident, requesting anonymity because of the sensitivity of the matter, said it was ironic that Darroch was pushed from his post over the leaked memos, because much of the critical material in the cables — about White House infighting and competencies — came from what Trump’s own aides, advisers and friends told British Embassy officials.

Simon McDonald, the head of the British diplomatic service, was asked at a parliamentary hearing whether he knew of any other examples in which a “head of state of a friendly government has refused to cooperate with any of Her Majesty's envoys?”

“None,” he replied.

Trump administration officials initially reacted well to the cables being leaked and seemed inclined to accept an apology, officials said. But Trump was annoyed as news of the leak took more oxygen — and the president has maintained a long-simmering dislike of May.

By all accounts, Darroch worked hard during his time in Washington to build good relations with the administration and in turn was well liked by Trump officials across the government.

He and his staff traveled throughout the country trying to understand the Trump phenomenon, meeting with governors and senators. He was recently in West Virginia.

In Washington, he kept bipartisan ties, often spotted talking with Trump officials such as former White House homeland security aide Tom Bossert and senior White House counselor Kellyanne Conway along with Obama officials such as Susan E. Rice at the same parties.

He would invite Trump confidants over to the embassy for outdoor patio drinks to try to decipher the White House. Much of his understanding of the administration in the leaked cables came from Trump’s own people, officials said.

Darroch was always looking to ingratiate himself, even joking that the royal baby could be named Donald and meeting then-Chief of Staff John F. Kelly before dawn to show that he was an early riser like the general, said these officials, who spoke on the condition of anonymity to discuss the ambassador’s relationship with the administration.

For weeks ahead of Trump’s visits to Britain, he would meet with officials in the United States and in the British government to make sure every detail of the trips would please a president he viewed as egotistical.

Darroch also threw a lavish affair last year for the royal wedding of Prince Harry and Meghan Markle that brought a coterie of the administration to the British Embassy.

Darroch is the second top British official to find himself in hot water over leaked material. Two months ago, May sacked her defense secretary, Gavin Williamson, for allegedly playing a role in leaking details from a meeting about Britain’s willingness to defy the United States and work with Chinese telecommunications giant Huawei.

Dawsey reported from Washington. Jennifer Hassan in London and John Wagner in Washington contributed to this report.