President Trump overhauled his White House on Friday in a dramatic shake-up of his senior team at the six-month mark of his presidency, which so far has been beset by a special counsel’s widening Russia investigation, a floundering legislative agenda and seemingly constant chaos and infighting within his West Wing.

Trump’s decision Friday morning to install wealthy financier Anthony Scaramucci as White House communications director set off an unexpected chain reaction, with White House press secretary Sean Spicer resigning in protest, according to people familiar with the departure. By afternoon, Spicer’s deputy, Sarah Huckabee Sanders, had been named to replace him.

As the reorganization unfolded throughout the day, Trump’s communications shop — not known for finely tuned messaging — offered its best attempt at a display of unity, a Kabuki-theater performance juxtaposing polite public statements with sniping and complaints behind the scenes.

“The president wanted to bring on some folks, to add to the team,” Spicer said in a brief interview on Friday. “This is something you dream of. I can’t thank the president enough.”

Asked if he had any regrets, Spicer replied: “None.”

In a statement Sanders read during the daily briefing, Trump said he was “grateful for Sean’s work” and wished him “continued success as he moves on to pursue new opportunities — just look at his great television ratings.”

White House Chief of Staff Reince Priebus called a private meeting of the White House communications staff Friday morning and said that Spicer, who will remain through August to help Scaramucci transition into the role, is leaving to give the new communications director “a clean slate,” according to someone briefed on the meeting who, like others, spoke on the condition of anonymity.

Priebus also tried to play down any tensions between him and Scaramucci, saying the two have known each other for a long time, and Scaramucci told his new team that he is not a “top-down” manager, this person said.

Spicer’s abrupt and angry departure — which caught even senior West Wing staffers by surprise — reflects the latest upheaval in a White House that has been consumed by tumult and warring factions since almost the day Trump took office. Bringing Scaramucci into the White House could further heighten tensions among Trump’s senior staff.

Scaramucci has a contentious relationship with both Spicer and Priebus, each of whom vehemently objected to Trump’s decision to install him in the top communications job. Scaramucci has coined a particularly crude nickname for Priebus and, in private conversations with associates in recent weeks, repeatedly savaged both the chief of staff and the entire White House press operation.

Scaramucci has argued to confidants that the media operation mobilizes aggressively whenever critical coverage of Priebus emerges, but that it is far less diligent about defending the president himself, which he characterized as disloyal.

Priebus, meanwhile, previously blocked Scaramucci from several key White House jobs, including director of the office of public liaison. In a last-ditch attempt to keep Scaramucci out of the communications director role, Priebus offered him the public liaison job, a senior White House official said.

A Priebus ally, however, rejected the notion that the chief of staff had tried to block Scaramucci, saying he was simply trying to slow down the process.

Some Trump loyalists inside the West Wing view the hiring of Scaramucci over Priebus’s wishes — and the sudden resignation of Spicer — as a blow to Priebus’s already fraught standing with the president and his leadership of the senior staff.

“This exposes Reince as neither a leader nor a manager,” one senior White House official said, speaking on the condition of anonymity to offer a candid assessment.

Stephen K. Bannon, Trump’s senior strategist, also opposed the hiring, according to two people familiar with the discussions. Although Bannon — the former chairman of the conservative Breitbart News website — likes Scaramucci personally, he worried that the financier does not have the right set of skills for the job and symbolizes the corporate Wall Street interests that Bannon and others in the nationalist wing of the White House have railed against.

The communications post had been open since Michael Dubke vacated it in May.

The latest staff changes come amid growing legal headaches for Trump, as well as his eldest son, Donald Trump Jr., and son-in-law and senior adviser Jared Kushner, who during the campaign attended a June 2016 meeting with a Russian lawyer promising incriminating information on Democratic presidential candidate Hillary Clinton.

Trump’s legal team, which underwent its own shake-up Thursday, has begun working to undermine the investigation by special counsel Robert S. Mueller III into possible collusion between Trump’s campaign and Russia by looking into ways to highlight alleged conflicts of interest on Mueller’s team, The Washington Post reported Thursday. The president has also inquired about his pardon authority — including his ability to pardon aides, family members and even himself, according to people familiar with the effort.

Another wave of controversy washed over the administration late Friday when The Post reported that U.S. intelligence intercepts show Attorney General Jeff Sessions discussed Trump campaign-related issues with the Russian ambassador.

Scaramucci addressed reporters Friday afternoon during a news conference, thanking Spicer for doing an “amazing job” and adding, “I love the guy. I hope he goes on to make a tremendous amount of money.”

Scaramucci insisted he has a good relationship with Priebus and said he offered to bring him on board as chief operating officer at his SkyBridge Capital company following the 2012 presidential campaign. Priebus, then the head of the Republican National Committee, declined the offer, he said.

“We’re a little bit like brothers,” Scaramucci said. “We rough each other up a bit, and that’s totally normal for brothers. He’s a dear friend.”

But in the same briefing, he also made clear whom he views as his ultimate boss, saying he has “no problem working for Reince,” but adding: “The president said I report to him directly.”

Several times during Friday’s briefing, Scaramucci said he loved the president and that his goal is to make sure Trump’s message is heard by the public and better represented in the media.

“I think there’s been, at times, a disconnect between the way we see the president and how much we love the president and the way some of you perhaps see the president,” he said. “And I certainly see the American people probably see the president the way I do. But we want to get that message out there.”

Ivanka Trump, her husband, Kushner, and Commerce Secretary Wilbur Ross had all been pushing Scaramucci for the job — and on Friday, as some West Wing officials made a final plea to the president to rethink his decision, both his daughter and son-in-law reached out to Scaramucci, to reassure him, according to a senior White House official.

The president has been particularly taken in recent weeks with Scaramucci’s hard-charging defenses of his administration on cable TV news, several people familiar with his views said. The president was impressed with how Scaramucci — known as “the Mooch” — fought back against a CNN article about himself, ultimately leading to the resignation of three CNN staffers involved with the story. Trump views Scaramucci as a natty combatant with a smile.

Kellyanne Conway, counselor to the president, complimented Spicer’s service to Trump and praised Scaramucci in a brief interview. “Like the president, Anthony is a tough, self-made, successful New Yorker who can be both a street fighter and run a C-suite meeting,” she said. “The president likes that.”

Scaramucci was slated to join the White House in another capacity earlier this year, but he had challenges resolving ethical conflicts associated with SkyBridge Capital, which he sold to a Chinese conglomerate with ties to the government just before Trump’s inauguration.

On Friday, he told reporters he has been assured by government ethics officials and the White House counsel that there should be no obstacles to him joining the administration now.

“My start date is going to be in a couple of weeks, so that it’s a — 100 percent totally cleansed and clean,” he said.

Spicer’s allies, in explaining his departure, said he feared Scaramucci would be communications director in name only because he has little experience working in either communications or politics. Spicer also wanted the new communications director to report to him, which would not have been the case with Scaramucci. Instead, Spicer worried he would find himself serving in two roles simultaneously, even while Scaramucci fell outside his chain of command, these allies said.

“This is a joke,” said one person close to the press office. “Trump wanted Scaramucci on television as a surrogate for the White House and wanted to give him a more formal title.”

Spicer’s resignation marks a sudden end to a short and rocky tenure. The press secretary undercut his credibility during his first full day on the job when, at Trump’s urging, he publicly made false statements about the size of the president’s Inauguration Day crowds.

Trump regularly nitpicked and criticized Spicer’s on-camera briefings, polling his friends about how long he should retain Spicer in the high-profile role. There were other slights. During his first trip abroad, Trump pointedly kept Spicer, a devout Catholic, from a meeting with Pope Francis.

Spicer, a longtime Republican communications operative in Washington, began his time at the podium with a warm relationship with the press corps. But just six months later, many now associate him primarily with his red-faced shouting binges and his caricature on “Saturday Night Live,” where he was ruthlessly parodied by actress Melissa McCarthy dressed as a man.

In private, Scaramucci seemed to have at least entertained the idea of the top communications post since June. Speaking at former GOP presidential nominee Mitt Romney’s private retreat in Deer Valley, Utah, last month, Scaramucci said that he believed the White House was faltering in part because the communications director job was empty and that communicating directly with the public was the key imperative of this White House, according to one attendee.

If he were in the role, Scaramucci continued, he would consider starting a daily administration “television” broadcast at 7 a.m., complete with a desk on the White House lawn and guests that included Democratic leaders.

“I like Anthony, but Pelosi and Schumer aren’t going on his state-run morning show,” the attendee said, referring to Senate Minority Leader Charles E. Schumer (D-N.Y.) and House Minority Leader Nancy Pelosi (D-Calif.). The attendee spoke on the condition of anonymity to share details of a private discussion.

Spicer, meanwhile, said in the brief interview that he hopes he is just “midway through the book” of his life. This most recent chapter, he said, might best be entitled, “Exciting Times.”