President Trump decided to get rid of chief strategist Stephen K. Bannon, after weeks of White House upheaval and racial unrest. (Peter Stevenson,Jenny Starrs/The Washington Post)

President Trump on Friday dismissed his embattled chief strategist, Stephen K. Bannon, an architect of his 2016 general-election victory and the champion of his nationalist impulses, in a major White House shake-up that follows a week of racial unrest.

With Trump’s presidency floundering and his legislative agenda in shambles, administration officials said his empowered new chief of staff, John F. Kelly, moved to fire Bannon in an effort to tame warring factions and bring stability to a White House at risk of caving under its self-destructive tendencies.

A combative populist on trade and immigration, Bannon was arguably Trump’s ideological id on the issues that propelled his candidacy. He served as a key liaison to the president’s conservative base and the custodian of his campaign promises.

Bannon had been a lightning rod for controversy since joining Trump’s campaign last summer, but he attracted particular scorn in recent days for encouraging and amplifying the president’s divisive remarks in the wake of last weekend’s deadly white supremacist demonstration in Charlottesville.

Sarah Huckabee Sanders, the White House press secretary, said in a Friday afternoon statement to reporters: “White House Chief of Staff John F. Kelly and Steve Bannon have mutually agreed today would be Steve’s last day. We are grateful for his service and wish him the best.”

The departure is the latest jolt to a White House riven by extraordinary turnover. In Trump’s first seven months in office, he has lost, to high-profile firings or resignations, a chief of staff, a chief strategist, a national security adviser, a press secretary, two communications directors and a deputy chief of staff.

The tumult could continue, as some White House officials said Friday that they expect some of Bannon’s internal allies to exit with him. Two such people are national security aide Sebastian Gorka and presidential assistant Julia Hahn, although both have portrayed themselves in recent talks with colleagues as Trump allies first and Bannon allies second.

Despite his ideological similarities with Bannon, senior policy adviser Stephen Miller is seen as safe. He joined the campaign long before Bannon and has his own relationships with the president and other senior advisers. He has also distanced himself from Bannon in recent weeks.

Bannon returned Friday to Breitbart News — a fiery, hard-right site that has gone to war with the Republican establishment — and resumed his previous role as executive chairman, presiding over an evening editorial meeting. An announcement on the site said Bannon informed the White House on Aug. 7 of his intention to leave, contradicting the accounts of White House officials, who said he was fired this week, as well as Bannon’s own statements to friends this week.

In an interview with the Weekly Standard, Bannon cast his departure as the end of an era. “The Trump presidency that we fought for, and won, is over,” he said. And he described himself as liberated.

“I feel jacked up,” Bannon said. “Now I’m free. I’ve got my hands back on my weapons. Someone said, ‘it’s Bannon the Barbarian.’ . . . I built a f---ing machine at Breitbart. And now I’m about to go back, knowing what I know, and we’re about to rev that machine up.”

For months, Bannon was locked in a long and tortuous battle with senior adviser Jared Kushner, the president’s son-in-law, and a coterie of like-minded senior aides, many with Wall Street ties.

Robert Kuttner, co-editor of the American Prospect, got an unexpected interview with White House chief strategist Stephen K. Bannon on Aug. 15. (Peter Stevenson/The Washington Post)

Bannon had a mythical reputation inside the White House, but he routinely skipped important policy meetings, and his nationalist views were often absent from key White House proposals. He became fixated in recent months on trade and immigration issues, and he had a large dry-erase board in his office that served as a checklist for promises in those areas. But some of his ideas — such as a proposal to raise the top tax rate on the wealthiest Americans — were easily batted away by other senior advisers in the White House.

Bannon had been advocating internally against sending additional troops to Afghanistan, putting him at odds with national security adviser H.R. McMaster and others. Yet he was excluded from a South Asia strategy session Trump convened at Camp David on Friday with nearly two dozen senior officials.

Bannon has told associates in recent days that if he were to leave the White House, the conservative populist movement that lifted Trump in last year’s campaign would be at risk. One person close to him said that the coalition would amount to “Democrats, bankers and hawks.” Bannon also predicted that Trump would eventually turn back to him and others who share the president’s nationalist instincts, especially on trade.

Bannon allies said they expect him to remain largely loyal to the president, while training his harshest fire on those in Trump’s orbit he believes bring a Democratic, “globalist” worldview to the administration. But with Bannon out of the West Wing, Breitbart is more likely to begin mobilizing its audience against the White House on issues such as immigration, where it thinks Trump is not keeping his campaign promises, said someone familiar with the organization’s approach.

Rep. Steve King (R-Iowa), who is close to Bannon, said Trump’s base could revolt. “With Steve Bannon gone, what’s left of the conservative core in the West Wing? Who’s going to carry out the Trump agenda?” he asked in an interview.

King suggested that Trump fill Bannon’s political-strategist seat with former deputy campaign manager David Bossie, who has his own connections to Trump’s base.

“This looks like a purging of conservatives,” King said. “The odds of him completing his campaign promises, even to the limit of his executive authority, have been diminished by this.”

Though Bannon’s firing is being interpreted as a victory for the cadre of more moderate White House advisers, several operatives with ties to the conservative movement remain in Trump’s circle, including counselor Kellyanne Conway, deputy chief of staff Rick Dearborn and legislative affairs director Marc Short.

Still, the consequences on Capitol Hill could be wide-ranging. House and Senate Republican leaders have long been wary of Bannon, and their allies were cheering Friday at the news of his departure. But among the hard right in Congress — including Rep. Mark Meadows (R-N.C.), chairman of the House Freedom Caucus — there was anger and doubt that anyone left in the White House shares their appetite for political confrontation.

The decision to fire Bannon was made by Kelly, the retired four-star Marine Corps general brought in late last month as White House chief of staff, officials said. It came after exactly three weeks in a position where he has been given unilateral power to overhaul the West Wing staff in an effort to stanch warring among factions, aides and advisers going rogue, and repeated leaks to the news media.

“This was without question one man’s decision: Kelly. One hundred percent,” one senior White House official said. “It’s been building for a while.”

This past week, as mainstream Republicans lambasted Trump for his handling of the Charlottesville violence, many on the White House staff led a drumbeat for the president to dismiss Bannon and any other aides who have connections of any kind to the white nationalist movement, this official said.

“The fevered pitch was basically outrage from dozens on the staff that anybody who’s ever had a part of that has to be purged immediately,” this official said.

Kelly has no personal animus toward Bannon, said people familiar with his thinking. But he was especially frustrated with Bannon’s tendency to try to influence policy and other matters not in his portfolio, as well as a negative media campaign he and his allies waged against McMaster.

A person close to Kelly said he was intent on making the White House not only less chaotic but also less driven by a particular ideology. He made clear to his deputies that he did not want to align with any faction but rather to shake up a culture on the staff where power seemed to drift from group to group. Kelly said he wanted power to drift from Trump to him, period. The president would be given ideas to choose from, rather than hearing a parade of whispers on the phone and in the Oval Office from competing blocs.

Trump, meanwhile, had been upset about Bannon’s participation in a book by Bloomberg News reporter Joshua Green, “Devil’s Bargain” — particularly a cover photo giving equal billing to Trump and his chief strategist. Every time Green was on CNN, where he is now a contributor, Trump grew unhappy with his references to Bannon as a thinker and strategist — and upset that the conversation was not instead about Trump.

Bannon’s critics noticed that Trump hated this narrative, and they would casually mention the book whenever they could in private conversations, slowly building a case against Bannon as a self-promoter.

This week, at a moment when even his allies and confidants agreed that his job security was as precarious as ever, Bannon further imperiled his standing by giving an interview to the liberal American Prospect magazine, in which he sniped by name at his enemies within the White House — including Gary Cohn, director of the National Economic Council — and publicly contradicted the administration’s stance on North Korea.

Bannon confidants said he thought his conversation with the magazine was off the record, but the damage was done. Kelly, said two people familiar with his thinking, was most frustrated by Bannon’s comments on North Korea.

Associates said Bannon may partner on a new venture with the Mercer family, billionaire conservative mega-donors who served as his patrons in an array of enterprises before he joined the Trump campaign. One strong possibility is a new media entity.

“They have a very strong working relationship together, and I would be shocked if we don’t hear of a major initiative involving Steve and the Mercers in the next 30 and 60 days,” said a person familiar with the family’s views, who spoke on the condition of anonymity to describe the thinking of the Mercers. “They don’t walk in lockstep in terms of their views, but they like the fact that Steve gets results, and they think money put into ventures he’s involved in is money well spent.”

Much of Bannon’s time in recent days was spent in the Eisenhower Executive Office Building on the White House grounds — as the West Wing is under renovation — where he has a spacious corner office on the first floor that is piled with books he is reading and files on trade policy and immigration policy.

Bannon closely monitored media coverage of both himself and Trump, thumbing his phone whenever associates would text or email him new articles. Whenever he read articles about rivals such as Cohn reportedly being critical of the president’s conduct, he fumed that they were undermining him as he was trying to enact what Trump promised his base voters.

Inside Trump’s circle, there were two camps: those who argued that Bannon should fight to stay and be a political warrior for Trump’s nationalist instincts, and those who thought his battles with the more moderate wing of the White House had reached their nadir.

The potential for Bannon to wreak havoc and mischief from outside the White House is among the reasons Trump had been skittish about firing his chief strategist. Bannon himself has used wartime metaphors to signal to friends and confidants that he will continue to pursue his nationalist, populist agenda.

At Breitbart, for instance, staffers celebrated Bannon as a pirate captain returning to his ship.

“The president and his agenda have many enemies throughout Washington — on Capitol Hill, in the media, in the White House and throughout government,” one Bannon friend said. “There is no better person to fight back against the swamp than Stephen K. Bannon. Everybody is on notice: Anyone working against the will of the American people will be exposed and held accountable.”

Matea Gold contributed to this report.