The decision came after Trump hired Anthony Scaramucci, a New York financier, as communications director. Sarah Huckabee Sanders will take over as press secretary.

Spicer will leave the White House in August, he wrote on Twitter.

For months, Spicer’s daily news briefings were must-see television, although he took on a more behind-the-scenes role in recent weeks. Sanders had largely taken over the briefings, with most of them taking place off-camera.

Spicer hasn’t given a press briefing since June 23.

Speaking to reporters at the White House on Friday, Scaramucci said Spicer’s departure is “obviously a difficult situation.”

“I hope he goes on to make a tremendous amount of money,” Scaramucci said, taking questions from reporters. When asked what he would do to “right the ship” at the White House, Scaramucci said the administration is going in the right direction, and he will be focused on improving the communications strategy.

“The ship is going in the right direction. We’ve got to radio signal the direction very, very clearly,” he said.

Trump has grown increasingly frustrated with his administration’s agenda being overshadowed by the FBI’s investigation into Russian meddling in the election and what he sees as the inability of the White House communications team to counter the steady drip of damaging headlines linking his campaign to the Russian government.

In recent weeks, Spicer has borne the brunt of the president’s ire. Trump has told close advisers that Spicer had been beaten into submission by the press, according to a person close to Trump, and no longer was able to punch back forcefully enough.

Those concerns came to a head this week, as Spicer continued to be absent from the podium and Scaramucci’s name was floated as someone who could jab and parry more effectively with the media.

Spicer was an ally of White House chief of staff Reince Priebus, having worked for Priebus when he headed the Republican National Committee.

Trump has admired Scaramucci’s defense of him on television. But Priebus and White House strategist Steve Bannon were both reported to have opposed Scaramucci’s appointment.

To explain the tension with Priebus over his appointment, Scaramucci said he and Priebus are “like brothers” and sometimes “rough each other up.”

Like other Trump advisers, including Kellyanne Conway, Trump wasn’t the first candidate Scaramucci backed in the 2016 election. He served as national finance chairman for Wisconsin Gov. Scott Walker and supported Jeb Bush after Walker withdrew from the race.

Scaramucci called Trump “another hack politician” during a 2015 Fox Business appearance. On Friday, he apologized for that statement, saying that Trump had continued to remind him about it.

Once he came around to supporting Trump, Scaramucci became a full-throated advocate for Trump’s policies in television news shows.

But his views haven’t always been in lockstep with the president.

In March 2016, Scaramucci wrote on Twitter in favor of policies to combat climate change that don’t hurt the economy, calling it “disheartening” that some people still believe climate change is a hoax.

“You can take steps to combat climate change without crippling the economy. The fact many people still believe CC is a hoax is disheartening,” Scaramucci wrote at the time. Trump has repeatedly called climate change a hoax.

Years earlier, in 2012, Scaramucci wrote on Twitter in favor of gun control.

“We (the USA) has 5 percent of the world’s population but 50 percent of the world’s guns. Enough is enough. It is just common sense it apply more controls,” Scaramucci wrote.

Trump also shuffled his legal team in the past week, hiring Washington attorneys John Dowd and Ty Cobb to join White House lawyers.

Trump’s longtime attorney Marc Kasowitz will have a reduced role on Trump’s legal team. He publicly defended Trump’s firing of FBI director James Comey in early June, but reportedly he is not eligible for security clearance.