WASHINGTON — John F. Kelly, the new White House chief of staff, told Stephen K. Bannon in late July that he needed to go: No need for it to get messy, Mr. Kelly told Mr. Bannon, according to several people with firsthand knowledge of the exchange. The two worked out a mutually amicable departure date for mid-August, with President Trump’s blessing.

But as Mr. Trump struggled last week to contain a growing public furor over his response to a deadly, race-fueled melee in Virginia, Mr. Bannon clashed with Mr. Kelly over how the president should respond. Give no ground to your critics, Mr. Bannon urged the president, with characteristic truculence.

At the same time, New York real estate investor friends told Mr. Trump that the situation with Mr. Bannon was untenable: Steve Roth on Monday, Tom Barrack on Tuesday and Richard LeFrak on Wednesday.

By Thursday, after Mr. Bannon undercut American policy toward North Korea in an interview published by a left-leaning magazine, Mr. Trump himself had concluded that Mr. Bannon was too much of a liability.

By Friday, when he was forced from his job as Mr. Trump’s chief strategist, Mr. Bannon had found himself wholly isolated inside a White House where he once operated with such autonomy that he reported only to the president himself.

This account is based on interviews with a dozen White House aides, associates of the president’s and friends of Mr. Bannon’s.

A former Naval officer, Mr. Bannon speaks often in the language of combat — of escalating conflict to “nuclear” levels and driving his enemies “ballistic.” But in the end, he had lost the war against a list of enemies that included nearly everyone in the West Wing. They included not just the adversaries whose conflicts with Mr. Bannon were widely aired — Gary D. Cohn, the president’s chief economic adviser; Lt. Gen. H. R. McMaster, the national security adviser; Ivanka Trump, the president’s daughter; and Jared Kushner, his son-in-law.

Also against him was Mr. Kelly, who was outraged by the indiscretion Mr. Bannon displayed in the interview with The American Prospect, according to three senior administration officials. And Mr. Bannon could no longer turn to Mr. Trump, whose confidence in him had eroded over a period of months, to ask for a reprieve.

Even the market tumbled on the prospect that Mr. Bannon could come out on top. Blue chip stocks slid last week after an erroneous report said that Mr. Cohn’s resignation was imminent because of his disgust with Mr. Trump’s failure to more forcefully denounce the racist Charlottesville, Va., demonstrators. Friends and former colleagues of Mr. Cohn’s said the economic adviser criticized Mr. Trump in such strong terms that at least one wondered how he could possibly remain in his position.

As soon as Mr. Bannon arrived at the White House on Inauguration Day, he seemed to realize that he would not be long for the job. He felt that Mr. Trump had treated him as a peer during the presidential campaign, but, he often complained to friends, “when I got to the White House, all of a sudden I was just a staffer.”

Opponents’ mythology around Mr. Bannon often held that he was the evil genius who pushed the president to make some of his more audacious decisions. And Mr. Bannon’s political opponents believe his departure has removed one of the biggest impediments to stability inside the White House.

But more likely, Mr. Bannon’s exit will clarify that only one person, Mr. Trump, for better or worse, has always been his own chief strategist. While several administration officials interviewed said they see Mr. Kelly as perhaps the last hope for fixing the fractured administration, they concede that only Mr. Trump can right his listing presidency.

Video

Stephen K. Bannon, President Trump's outgoing chief strategist, has been criticized as being emblematic of the far-right nationalism that turned violent in Virginia last weekend.CreditCredit...Al Drago/The New York Times

“My view is that the president has his own mind,” said Matt Schlapp, the chairman of the American Conservative Union and a former White House political director under George W. Bush. “People make too much of the idea that he’s some kind of blank slate that advisers can push one way or the other.”

Steve Schmidt, who helped manage Senator John McCain’s presidential campaign in 2008 and is a critic of the president, said: “We are seeing all of the personal qualities and character of the president on a daily basis. It’s not restrainable or controllable because he is who he is.”

Mr. Bannon’s opponents had long argued that he inflated his importance in White House debates and took more than his fair share of credit in plotting Mr. Trump’s victory. But he was someone with whom the president, for the most part, had long enjoyed spending time.

The two men, whose friendship was cemented during the two and a half months in which Mr. Bannon helped rescue Mr. Trump’s presidential campaign, reinforced each other’s rough-around-the-edges tendencies. Both could be gratuitously foul-mouthed, viciously cutting to their enemies and unapologetically politically incorrect. “Dude, he’s Archie Bunker,” Mr. Bannon would say with fondness when talking about Mr. Trump.

Mr. Bannon fed Mr. Trump’s paranoid streak and shared the president’s penchant for believing in conspiracies. He viewed not just intelligence agencies but most of government as stocked with a devious bureaucratic underbelly, the “deep state.” Mr. Trump, who has never worked in government, eagerly adopted that view.

Mr. Bannon was notorious for maintaining his own, shadowy presence within the White House. He would frequently skip meetings where policy was discussed, injecting his views into the process in other ways, according to two administration officials. He did not use a computer, preferring to have paper printed and handed to his assistant to stay outside the formal decision-making process.

Mr. Bannon favored a culture similar to the one Mr. Trump brought with him from the business world to the White House — a flat structure with blurred lines of responsibility and competing power centers. And early on Mr. Bannon benefited from that structure, sitting at the top, free to slip unvetted materials to the president without a gatekeeper to get past.

“Theoretically, a more coherent staff should produce a more coherent policy,” said David Axelrod, who was President Barack Obama’s senior adviser and the person in a comparable role to Mr. Bannon in the White House. “But that presupposes a president who embraces the process and the policy.”

Mr. Bannon openly complained to White House colleagues that he resented how Ms. Trump would try to undo some of the major policy initiatives that he and Mr. Trump agreed were important to the president’s economic nationalist agenda, like withdrawing from the Paris climate accords. In this sense, he was relieved when Mr. Kelly took over and put in place a structure that kept other aides from freelancing.

“Those days are over when Ivanka can run in and lay her head on the desk and cry,” he told multiple people.

Ms. Trump and Mr. Kushner, who had helped oust Mr. Kelly’s predecessor, whom they saw as ineffective, also told people that they wanted a new system for the same reason.

Mr. Bannon made little secret of the fact that he believed “Javanka,” as he referred to the couple behind their backs, had naïve political instincts and were going to alienate Mr. Trump’s core coalition of white working-class voters.

He told White House colleagues including the president that too many conservative Republicans in Congress would balk if Mr. Trump took their advice and showed more flexibility on immigration, particularly toward young undocumented immigrants brought to the United States as children.

He also advised that ideological softening would buy the president no good will from Democrats or independent voters, whom Mr. Kushner and Ms. Trump believe Mr. Trump still has a chance of reaching.

“They hate the very mention of his name,” Mr. Bannon told them. “There is no constituency for this.”

His advice for the president: “You’ve got the base. And you grow the base by getting” things done.

Mr. Bannon’s disdain for General McMaster also accelerated his demise. The war veteran has never quite clicked with the president, but other West Wing staff members recoiled at a series of smears against General McMaster by internet allies of Mr. Bannon. The strategist denied involvement, but he also did not speak out against them.

By the time Charlottesville erupted, Mr. Kushner and Ms. Trump had a powerful ally in Mr. Kelly, who shared their belief that Mr. Trump’s first statement blaming “many sides” for the deadly violence needed to be amended.

Mr. Bannon vigorously objected. He told Mr. Kelly that if Mr. Trump delivered a second, more contrite statement it would do him no good, with either the public or the Washington press corps, which he denigrated as a “Pretorian guard” protecting the Democrats’ consensus that Mr. Trump is a race-baiting demagogue. Mr. Trump could grovel, beg for forgiveness, even get down on his knees; it would never work, Mr. Bannon maintained.

In truth, long before Charlottesville, Mr. Trump had begun losing patience. The arrival of Mr. Kelly to play precisely the gatekeeping role that would stymie aides like Mr. Bannon hastened his departure.

The president believed that Mr. Bannon had been leaking unauthorized stories about infighting in the administration for months before he ultimately took action.

Mr. Trump was irritated by a book, “Devil’s Bargain,” that portrayed Mr. Bannon as a brilliant political Svengali but put Mr. Trump in a supporting role.

When one Trump ally noted to him recently that Mr. Bannon did help him at the end of the race, Mr. Trump interrupted, “You know, he came very late.”

The week of Aug. 7, Mr. Bannon suggested timing the departure to Aug. 14, which was a day after his one-year anniversary working for Mr. Trump on the campaign. It made sense to everyone.

Mr. Bannon’s physical appearance was crumbling, and his mood swings had become pronounced.

In late July, after a weekend with Robert Mercer, the hedge fund billionaire who finances some of his projects, Mr. Bannon told him, “I dread going back” to the White House.

But after Charlottesville, Mr. Bannon maintained that an Aug. 14 exit would look like part of the president’s response to the violence. He did not want that, and others were understanding. So they discussed moving the date to around Labor Day weekend, although two administration officials said Mr. Bannon sought to entirely renegotiate the terms of his departure.

Then came Mr. Bannon’s unguarded comments to The American Prospect, published on Wednesday evening. He denigrated some colleagues, specifically identified one that he was going to see fired and said of striking North Korea, “There’s no military solution here, they got us” — a direct contradiction to the message Mr. Trump had been sending. Mr. Bannon could buy no more time.