Kim Darroch on Wednesday resigned as the UK's ambassador to the US.

Darroch resigned after diplomatic cables were leaked which he had described President Donald Trump as "inept," "insecure," and "incompetent."

But Darroch was just doing his job, and Trump's reaction to the leaks proves the ambassador was right.

Emily Tamkin is a freelance writer who covers foreign affairs and has written for a variety of publications including Foreign Policy, BuzzFeed News, The Washington Post, and Politico.

Visit Business Insider's homepage for more stories.

British Ambassador Kim Darroch's time in Washington was meant to be up at the end of the year. Instead, he resigned Wednesday.

The reason for his resignation? He was good at his job.

On Sunday, the Daily Mail published leaked diplomatic cables in which Darroch described US President Donald Trump as "inept," "insecure," and "incompetent," called the Trump White House "uniquely dysfunctional," and said that this presidency could "end in disgrace." He also described conflicts within the White House as "knife fights," warned that Trump could attack Iran, and described the administration's policy toward Iran as "chaotic."

Trump, on Monday, responded by saying the White House would no longer deal with Darroch. On Tuesday, the ambassador became a political point in the contest to decide the next prime minister. Foreign Secretary Jeremy Hunt said Darroch would stay if he got the job, but former Foreign Secretary Boris Johnson refused to commit one way or the other.

And so, on Wednesday, Darroch was out. "The current situation is making it impossible for me to carry out my role as I would like," he wrote to Simon McDonald, the permanent undersecretary at the Foreign and Commonwealth Office. "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."

McDonald said he accepted the resignation with "personal regret," adding, "The prime minister, foreign secretary, and whole of the public service have stood with you: You were the target of a malicious leak; you were simply doing your job."

And that's true. Part of the reason diplomats are in Washington in the first place is to write back to their capitals about what, exactly, is happening in the United States. As I reported for Foreign Policy earlier in the Trump administration, that has been an especially difficult task for foreign diplomats — even from allied countries — during this administration.

Read more: 'It could have been any of us': Diplomats in Washington agree with former UK ambassador Kim Darroch's scathing views on Trump, report says

The message that comes out of the White House is not necessarily the message that comes out of the State Department, which is not necessarily the message that comes off of the computer screen after Trump tweets. Just divining Trump foreign policy and sending back the facts as they are is challenge enough.

But Darroch wasn't just sending back what happened on which day. He was also sending back his professional analysis of the administration with which it was his job to navigate relations. And the blowback from the Trump administration after learning in a leak what that analysis was proves Darroch's assessment was correct.

Darroch wrote that there were "knife fights" in the White House; the same has been written in any number of books and by any number of White House reporters.

Darroch described the Trump administration's Iran policy as chaotic. In this administration, the national security adviser reportedly did not know when the president was going to pull out of the Iran nuclear agreement, an agreement by which the administration is now encouraging Iran to abide. "Chaotic" does not strike one as a wildly inappropriate word choice.

Darroch warned that Trump could still attack Iran; Trump himself says all options are on the table with regard to Iran.

And yet after learning that Darroch wrote all of this, Trump's response was not only to say he would no longer deal with him, but to tweet out — on Tuesday, days after the leak — that Darroch was "very stupid" and a "pompous fool" and also, "Tell him the USA now has the best Economy & Military anywhere in the World, by far and they are both only getting bigger, better and stronger.....Thank you, Mr. President!" thus ensuring that this would be a multiday story.

His reaction strikes one as — to use Darroch's phrase — insecure. His actions all but guaranteed that a story involving a critique of his presidency would last several days, which makes him seem — Darroch, help me out here — inept.

None of this is to say that Kim Darroch was a perfect ambassador, or that there isn't plenty the British government could do to improve US-UK relations, or that there isn't someone who would be better for the role under this particular president.

But Darroch got caught in the act of sending his analysis of what is happening in this country back to his own country — that is, doing his job. That the reaction of the president he was analyzing was such that he felt the need to resign suggests that, actually, he was doing that part of his job rather well.

Emily Tamkin is a freelance writer and reporter based in Washington, DC. Previously, she covered foreign affairs as a staff writer at Foreign Policy and BuzzFeed News, and her work has appeared in the Washington Post, the Columbia Journalism Review, and Politico, among other publications. She is working on a book on George Soros for Harper Books.