Spicer addressed the news in a tweet Friday afternoon, saying he will continue his service through August. He added that it has “been an honor & privilege” to serve U.S. President Donald Trump.
Deputy press secretary Sarah Huckabee Sanders will take the job, the White House announced hours later during Friday’s press briefing.
Spicer’s resignation came just after Trump appointed Wall Street financier Anthony Scaramucci as his top communications official. Scaramucci replaces former communications director Mike Dubke, who resigned about two months ago.
WATCH: Trump’s communications director apologizes for calling him a ‘hack’
According to The New York Times, Spicer told the president that he vehemently disagreed with Scaramucci’s appointment. The president reportedly wanted Spicer to stay on.
In Friday’s press briefing, Scaramucci spoke about Spicer’s decision to leave, saying he hopes Spicer will go on to “make a tremendous amount of money.”
Sanders appeared briefly, reading a statement from the president on Spicer’s departure.
WATCH: Trump’s new communications director hopes Spicer will make ‘tremendous amount of money’
“I am grateful for Sean’s work on behalf of my administration and the American people,” the president’s statement said.
“I wish him continued success as he moves on to pursue new opportunities. Just look at his great television ratings.”
While not a surprise, Spicer‘s departure was abrupt and reflected heightened turmoil within Trump’s legal and communication teams amid a widening investigation into possible ties between Trump’s 2016 campaign and the Kremlin.
Spicer’s time at the White House has been tumultuous, with his daily press briefings regularly turning into intense exchanges between him and members of the press.
WATCH: Scaramucci says he would ‘love’ to have Sean Spicer stay
Due to growing tensions between Spicer and the press, the briefings became increasingly short. Often, journalists didn’t receive any answers from the press secretary about issues such as the Russia investigation, the travel ban, and the health-care bill.
In June, there was speculation that the president was considering assigning Spicer a less public role.
Recently, Spicer has been largely absent from the briefings, with Huckabee Sanders filling in.
Some of Spicer’s most heated exchanges happened during the Trump administration’s early days. On his first day in January, Spicer argued with journalists over the size of the crowd at Trump’s inauguration. In what may be his biggest blunder, Spicer claimed that Adolf Hitler didn’t use chemical weapons.
WATCH: Spicer explains why White House is trimming back on press briefings
“We didn’t use chemical weapons during World War Two,” he said in April. “You had someone as despicable as Hitler who didn’t even sink to using chemical weapons.”
Spicer later apologized for the remark.
He also referred to Prime Minister Justin Trudeau as “Joe Trudeau.”
Spicer’s blunders made him a famous target of Saturday Night Live parodies, with actress Melissa McCarthy assuming the role.
— With a file from Reuters