A COMEDY worthy of Yes Prime Minister’s most senior civil servant Sir Humphrey Appleby has been unfolding in the White House after a senior official in Donald Trump’s administration claimed to be one of a group of people “working diligently from within” to impede the president’s “worst inclinations”.

Trump lashed out at the anonymous senior official who wrote a New York Times article claiming to be part of a “resistance” working “from within” to thwart the US president’s most dangerous impulses.

He called the unsigned op-ed a “gutless editorial” and “really a disgrace”, while his press secretary called on the official to resign.

A guessing game over the writer’s identity consumed Washington and provoked swift denials of involvement from vice president Mike Pence, secretary of state Mike Pompeo and Dan Coats, the US director of national intelligence.

Trump was furious, tweeting: “The Deep State and the Left, and their vehicle, the Fake News Media, are going Crazy – & they don’t know what to do.”

He demanded that if “the GUTLESS anonymous person does indeed exist, the Times must, for National Security purposes, turn him/her over to government at once!”

White House press secretary Sarah Huckabee Sanders has called on the “coward” who wrote the piece to “do the right thing and resign”.

Allies of the president and political insiders have scrambled to unmask the writer, but the article also brought to light questions that have been whispered in Washington for more than a year, such as is Trump truly in charge and could a divided executive branch pose a danger to the country?

Former CIA director John Brennan, a fierce Trump critic, called the article “active insubordination ... born out of loyalty to the country”.

He told NBC: “This is not sustainable to have an executive branch where individuals are not following the orders of the chief executive. I do think things will get worse before they get better. I don’t know how Donald Trump is going to react to this. A wounded lion is a very dangerous animal, and I think Donald Trump is wounded.”

The Times admitted that publishing the anonymous piece was unusual, but added: “We have done so at the request of the author, a senior official in the Trump administration whose identity is known to us and whose job would be jeopardised by its disclosure ... President Trump is facing a test to his presidency unlike any faced by a modern American leader ...

“The dilemma – which he does not fully grasp – is that many of the senior officials in his own administration are working diligently from within to frustrate parts of his agenda and his worst inclinations.”

“Many Trump appointees have vowed to do what we can to preserve our democratic institutions while thwarting Mr Trump’s more misguided impulses until he is out of office,” the author wrote.

“It may be cold comfort in this chaotic era, but Americans should know that there are adults in the room.

“We fully recognise what is happening. And we are trying to do what’s right even when Donald Trump won’t.” Trump’s press secretary Sarah Huckabee Sanders accused the author of choosing to “deceive” the president by remaining in the administration, and added: “The coward should do the right thing and resign.”

However, in a plot that was a cross between Yes Prime Minister and House of Cards, the essay triggered a wild guessing game as to the writer’s identity on social media, in newsrooms and inside the West Wing, where officials were blindsided by its publication.

Trump allies and political insiders have been scrambling to unravel the identity of the author, pulling the text apart for clues: does the style read like someone who worked at a think tank; does “administration official” mean someone who works outside the White House; do references to Russia and the late Senator John McCain suggest someone working in national security?

The Times used the pronoun “he” in a tweet referring to the writer, which begged the question: “Does that rule out all women?”

However, the newspaper said the tweet referring to “he” had been “drafted by someone who is not aware of the author’s identity, including the gender, so the use of ‘he’ was an error”.

Trump’s call for the writer to be turned over to the government on – unsupported – national security grounds presented White House officials with an ultimatum that appeared to play straight into the author’s concerns about Trump’s impulsiveness.

The president called on aides to identify the writer, although it was not clear how they would go about doing it.

Debate on Twitter focussed on the author’s use of the word “lodestar”, which pops up frequently in Pence’s speeches.

Others argued that it could have been included to throw people off.

The writer said that where Trump has had successes, they had come “despite – not because of – the president’s leadership style, which is impetuous, adversarial, petty and ineffective”.

The decision to publish was made by James Bennet, editorial page editor, and James Dao, op-ed editor, with publisher AG Sulzberger weighing in, said a Times spokeswoman.

Dean Baquet, its executive editor, was not involved because the news pages are his responsibility, and the column appeared in the paper’s opinion section.

The op-ed was published a day after the release of details from an explosive new book by doyen of investigative journalists, Bob Woodward, that laid bare concerns among the highest echelon of Trump aides about the president’s judgment.

The writer of the Times piece said Trump aides were aware of the president’s faults and “many of the senior officials in his own administration are working diligently from within to frustrate parts of his agenda and his worst inclinations”.

They added: “I would know. I am one of them”.

The writer also alleged “there were early whispers within the cabinet of invoking the 25th Amendment” because of the “instability” witnessed in the president.

The writer added: “This isn’t the work of the so-called deep state. It’s the work of the steady state.”

As Francis Urquhart might have put it in House of Cards: “You might very well think that; I couldn’t possibly comment.”