President Trump decamped to his oceanfront estate here on Friday after a head-spinning series of presidential decisions on national security, trade and the budget that left the capital reeling and his advisers nervous about what comes next.
The decisions attested to a president riled up by cable news and unbound. Mr. Trump appeared heedless of his staff, unconcerned about Washington decorum, or the latest stock market dive, and confident of his instincts. He seemed determined to set the agenda himself, even if that agenda looked like a White House in disarray.
Inside the West Wing, aides described an atmosphere of bewildered resignation as they grappled with the all-too-familiar task of predicting and reacting in real time to Mr. Trump’s shifting moods.
Aides said there was no grand strategy to the president’s actions, and that he got up each morning this week not knowing what he would do. Much as he did as a New York businessman at Trump Tower, Mr. Trump watched television, reacted to what he saw on television and then reacted to the reaction.
Aides said he was still testing his limits as president while also feeling embattled by incoming fire — from Congress, the Russia investigation, foreign entanglements, a potential trade war and a pornographic film actress and a Playboy model who said they had affairs with Mr. Trump and were paid to keep quiet.
The president, furious over the failure of Congress to pay for his wall on the southern border with Mexico, began Friday by threatening in a Twitter post shortly before 9 a.m. to veto a $1.3 trillion spending bill passed hours earlier by Congress. That raised the specter of another government shutdown at midnight, this one precipitated entirely by Mr. Trump.
By 1:30 p.m., Mr. Trump had begrudgingly signed the bill and, in a hastily arranged appearance in the Diplomatic Reception Room, called it a “ridiculous situation.”
In the frantic hours before the signing, two senior officials said they were uncertain whether the president would veto the measure and prompt a shutdown or ultimately relent. White House officials raced to schedule an afternoon briefing for the news media, although they had no idea what they would end up telling reporters.
John F. Kelly, the chief of staff, in the meantime swung into action to pull the president back from the brink of a veto. Mr. Kelly summoned Defense Secretary Jim Mattis to the White House, aides said, to make the case for the military funding included in the bill.
In the Oval Office, Mr. Mattis; the homeland security secretary, Kirstjen Nielsen; and Vice President Mike Pence — who had postponed a trip to Atlanta because of the president’s veto threat — told Mr. Trump that the military spending level in the bill was historic and urged him to sign. Mr. Trump finally agreed. He then tweeted that he would hold a “news conference” on the subject himself.
What followed was a bizarre spectacle that was part-signing ceremony and part venting session as Mr. Trump presented his audiences with his dilemma in real time. He raged against the bill’s contents and the procedure that yielded it.
“Nobody more disappointed than me,” Mr. Trump said in a verdict from a president who has called himself a master dealmaker.
The whipsaw on spending came hours after the president forced out his national security adviser, Lt. Gen. H. R. McMaster, and replaced him with John R. Bolton, a hard-line former American ambassador to the United Nations, catalyzing fears of a sharp turn toward military confrontation on Mr. Trump’s national security team.
Mr. Mattis, viewed as a moderating force on the president, told colleagues before the appointment was declared that he would find it difficult to work with Mr. Bolton, people briefed on the conversation said.
Mr. Bolton’s appointment followed Mr. Trump’s announcement of tariffs on $60 billion worth of Chinese imports, which sank financial markets on Thursday and ignited fears of a trans-Pacific trade war. New steel and aluminum tariffs also took effect on Friday, though the White House exempted several allies from the measures, sowing equal measures of relief and confusion.
The tumult occurred against the ominous backdrop of the Russia investigation. The resignation of Mr. Trump’s lead lawyer, John Dowd, on Thursday signaled that the president was determined to sit down with investigators for the special counsel, Robert S. Mueller III, even as he takes a more combative stance toward the overall investigation.
Shortly before the president went on television on Friday to fume about the spending bill, several of his top advisers — including Mr. Mattis; the commerce secretary, Wilbur Ross; Ms. Nielsen; and Mr. Trump’s son-in-law, Jared Kushner — could be seen huddling in the Palm Court of the White House. They were deep in what appeared to be serious conversation.
Also on Friday, the departing national security adviser, General McMaster, bid farewell to the staff of the National Security Council. Staff members gave him a three-minute standing ovation, and there was talk of an exodus of career officials. Some were stunned by the sudden change in leadership, even though General McMaster’s status with Mr. Trump was known to have been shaky for weeks.
General McMaster was later spotted walking briskly out of the White House complex.
As Mr. Bolton prepares to replace General McMaster, people briefed by the White House said, the president has told Mr. Bolton that he needs to cut down on leaks, like the disclosure this week that Mr. Trump disregarded his briefing materials in a call with President Vladimir V. Putin of Russia.
That has prompted a debate over whether Mr. Bolton should carry out a housecleaning of the Security Council or leave the existing staff in place.
Democrats and others said Mr. Bolton’s record of advocating military action against Iran and North Korea raised the risk of war.
“Mr. Bolton’s tendency to try to solve every geopolitical problem w/ the American military first is a troubling one,” Senator Chuck Schumer, Democrat of New York, said in a tweet on Thursday. “I hope he will temper his instinct to commit our armed forces to conflicts around the globe, when we need to be focused on building the middle class here at home.”
Daryl G. Kimball, the executive director of the Arms Control Association, said in a statement, “Bolton’s extreme views could tilt the malleable Mr. Trump in the wrong direction on critical decisions affecting the future of the Iran nuclear deal, the North Korean nuclear crisis, and the strained U.S. relationship with Russia, among other issues.”
Rumors swirled at the White House that the president’s purge might soon continue with the firing of David Shulkin, the embattled secretary of the Veterans Affairs Department.
Mr. Trump is methodically shedding himself of those who have clashed with his views, including Rex W. Tillerson, his secretary of state, who was fired last week. But the president is also losing aides like Hope Hicks, his communications director and confidante, whose resignation is effective soon.