President Trump walks to Marine One on the South Lawn of the White House on Thursday. (Calla Kessler/The Washington Post)

This week’s revelations of a purported “resistance” force of senior government officials acting as guardrails against President Trump — manipulating him, infantilizing him and ignoring his directives — raised the specter of a shadow administration.

“Who’s in charge at the White House?” a reporter shouted at Trump on Thursday as he departed for a rally in Montana.

The president did not answer.

An anonymous op-ed in the New York Times, from someone identified only as a senior official, and a new Bob Woodward book, “Fear,” detail efforts at the highest levels of the government to contain Trump’s impulses and, in the most extreme cases, defy and even undermine his orders.

The successive disclosures crystallized what has long been evident throughout the Trump presidency — a cadre of administration officials alarmed by the whims and wishes of a chief executive they view as mercurial and impetuous working to curb his instincts on a range of issues, including national security, trade and immigration.

Beginning just after dawn Thursday, more than two dozen top officials and Cabinet members raced to issue forceful statements denying they were the anonymous author of the Times op-ed. They read as public declarations of loyalty to an audience of one — the media-obsessed president, who was gratified to see the statements as aides kept him abreast.

Trump especially liked the statement by Secretary of State Mike Pompeo, according to a senior administration official, who like many other current and former officials interviewed for this report spoke on the condition of anonymity to share candid accounts. While traveling in India, Pompeo criticized the “liberal newspaper” and described the anonymous editorial as “a disgruntled, deceptive, bad actor’s word.”

The administration’s fierce pushback centered on the official’s insistence on anonymity and the Times’s decision to publish the column without the author’s name, but Trump’s aides challenged little of the column’s substance.

Senior officials have long acted to slow-walk or stymie some of the president’s ideas and directives. When he was White House chief of staff, Reince Priebus had a favored strategy, according to his colleagues — tell the president that he would execute an order, or a firing — but not until “next week.” By then, Trump often would have forgotten.

Before some lawmakers, such as Sens. Lindsey O. Graham (R-S.C.) or Bob Corker (R-Tenn.), went golfing with Trump, White House legislative aides would prep them on helpful messages they were trying to share or “disasters they were trying to divert,” according to a former senior administration official. A current senior administration official defended the practice as “standard staff work in any White House.”

In his new book, Woodward chronicles multiple episodes in which aides deployed subterfuge against their boss. In one of those instances, Trump had a letter drafted to withdraw the United States from its trade agreement with South Korea. Gary Cohn, then Trump’s chief economic adviser, took it from the president’s Resolute Desk so that he could not sign it.

Trump also wanted to completely cut military aid to Pakistan because he felt it was not doing enough to fight terrorism and extremism, and in August 2017 the administration said it would defer more than $250 million in aid.

For months, U.S. diplomats and military officials managed to delay further action, all the while working to reassure nuclear-armed Pakistan, which for years had been a top recipient of foreign aid. But the strategy only dragged out the inevitable, one former official conceded.

Trump blindsided his staff on New Year’s Day when he angrily accused Pakistan of “lies & deceit” in a tweet and called for an end to U.S. aid. The message prompted a mad scramble, even as Defense Secretary Jim Mattis and then-Secretary of State Rex Tillerson continued to warn that cutting off aid could be destabilizing, according to former officials and congressional aides.

The State Department announced three days later it was suspending at least $900 million, or nearly all, of the remaining military aid, but managed to preserve hundreds of millions of dollars in economic assistance and military financing.

In the summer of 2017, Trump suggested to then-national security adviser H.R. McMaster that the United States invade Venezuela to remove its autocratic president, Nicolás Maduro. McMaster did his best to dissuade Trump — and thought he had succeeded — until Trump raised the possibility publicly at a media appearance and in a meeting with Latin American leaders at the U.N. General Assembly.

“My people tell me this is not a good idea, but . . .” Trump said in the private meeting before raising the possibility of an invasion or regime change in Venezuela, according to officials.

Said one senior White House official on why Trump kept bringing it up: “Even when the staff says no, I think he holds out hope that he’ll find someone who thinks it’s a good idea.”

Trump’s imagined invasion never occurred.

Aides also routinely slow-walked his trade ideas. The president would demand executive orders from Cohn or former staff secretary Rob Porter imposing tariffs or otherwise punishing China. But officials said the duo often ignored him in an effort to avert what they believed was bad policy, in hopes that if they paused the process, the president would move on to another topic.

“He would be like, ‘Do this, do that, slap a tariff on this country or that country, let’s blow everything up, let’s go to war,’ ” a former White House official said. “Then we would come back the next week and Trump would say, ‘What happened with X?’ And he would get mad that no one had done it. And it was a never-ending cycle.”

Ultimately, though, the administration implemented some of the tariffs — a precipitating factor in Cohn’s departure earlier this year.

Trump has proved persistent in other areas as well. He blasted Homeland Security Secretary Kirstjen Nielsen in May during a Cabinet meeting over a surge in illegal border crossings — a meltdown that went on for a half-hour — and demanded she “close” the border, according to a person with knowledge of what transpired.

Nielsen’s department proceeded to implement a harsh crackdown at the border that included separating parents from their children. But amid public outcry, Trump reversed course, frustrating Department of Homeland Security officials who had defended a policy that many of their friends and family members considered monstrous.

Trump’s advisers say he is impatient with bureaucracy and wants to see action or results immediately, which sometimes puts him in conflict with his staff or the processes they manage.

Graham said such staff efforts to manage Trump are routine in politics.

“There are people in my office who bring me back from the brink every day,” Graham said. He added: “Trump can be a handful, right? But, bottom line, the people around him are making him a successful president. . . . Trump sausage-making is difficult to watch, but in my view it makes results that benefit the country.”

Rep. Mark Meadows (R-N.C.), another Trump confidant, agreed: “Listen, that happens every day on Capitol Hill. Even some within my own staff think that one idea I have is great and another one is not so great.”

Trump’s mood this week has varied from volcanic anger to disappointment, and he has been “hellbent,” in the characterization of a senior official, to root out the anonymous author of the Times op-ed and hold him or her accountable for betraying the president.

In Oval Office huddles Thursday, White House chief of staff John F. Kelly, national security adviser John Bolton, press secretary Sarah Huckabee Sanders and senior adviser Jared Kushner, among other aides, tried to convince the president that he could trust them and others in his inner circle. They argued that the author was probably a lower-level employee, according to the senior official.

The twin bombshells also underscored a vexing reality for Trump — that some in his employ do treat him as an adolescent in need of chaperoning inside a White House that Corker memorably once described as “adult day care.”

But the conspiratorial and at times paranoid Trump felt a slice of vindication reading the Times column, seeing it as justifying his belief that the “deep state” and other enemies within are seeking to undercut him, according to two former White House officials briefed on the president’s private conversations.

“The functional effect of it all is for him to become more insulated, viewing the presidency more and more as a one-man band,” said one of those officials. This person characterized the president’s view as: “These people are here. Sometimes I need them to do stuff. But the presidency is not an institution. The presidency is me.”

Some of Trump’s allies on Capitol Hill argued that the tactic of sounding an alarm anonymously would backfire politically.

“Up here, anonymity is very common among the cultured, cosmopolitan, D.C. insider crowd who live in the condos with the high ceilings and the important art on the walls,” said Sen. John Neely Kennedy (R-La.). “To the average American, their attitude is, ‘If you’re going to make an allegation like that, have the oranges to put it on the record.’ ”

The Times column describes a “two-track presidency” in which Trump makes public pronouncements while his administration, in open view, works at cross-purposes. “It may be cold comfort in this chaotic era, but Americans should know that there are adults in the room,” the author writes. “We fully recognize what is happening. And we are trying to do what’s right even when Donald Trump won’t.”

The Justice Department historically has had a measure of independence from the White House, and while Attorney General Jeff Sessions has dutifully implemented some of the most controversial parts of Trump’s agenda, he and those working for him have at times resisted direction from the president.

Trump has tweeted mercilessly about the department turning over documents to Congress on the Russia investigation and the investigation into Hillary Clinton’s use of a private email server. While the department has turned over hundreds of thousands of pages of material, officials apparently have not produced all of what Trump’s conservative allies are seeking, prompting the president to continue to vent on Twitter.

Trump recently tweeted his displeasure with Sessions for allowing the department to bring charges against two of his Republican House allies ahead of the midterm elections. So far, at least, that frustration has not changed the way Justice Department prosecutors have handled the cases.

Thursday offered fresh evidence of the divergent courses set by the president and the Justice Department. In the morning, Trump tweeted praise for North Korea’s leader: “Kim Jong Un of North Korea proclaims ‘unwavering faith in President Trump.’ Thank you to Chairman Kim. We will get it done together!”

Hours later, the Justice Department announced criminal charges against Park Jin Hyok for allegedly being part of a North Korean government hacking team that crippled Sony’s computer systems, stole $81 million from a Bangladesh bank and unleashed far-reaching malware.

Devlin Barrett, Mike DeBonis, Anne Gearan, Shane Harris, John Hudson, Nick Miroff, Gabriel Pogrund and Matt Zapotosky contributed to this report.