White House communications director Anthony Scaramucci takes questions from reporters during a press briefing on Friday, July 21, 2017.

"It's been an honor & a privilege to serve @POTUS @realDonaldTrump & this amazing country," said Spicer said on Twitter. "I will continue my service through August."

Spicer has spent much less time in the briefing room in recent weeks, with principal deputy press secretary Sarah Huckabee Sanders handling more of the daily briefings.

He did brief the press off camera on Monday, and that was his first time doing so in three weeks.

At a White House press briefing Friday morning, Sanders read a statement from Trump: "I am grateful for Sean's work on behalf of my administration and the American people. I wish him continued success as he moves on to pursue new opportunities -- just look at his great television ratings."Sanders then introduced Scaramucci, who in turn announced that she will replace Spicer as the next White House press secretary.

Spicer's tenure got off to a somewhat rocky start when, on Trump's first full day in office, the press secretary angrily chastised journalists over the crowd size at the presidential inauguration. Spicer then stormed out of the briefing room without answering questions.

It's been an honor & a privilege to serve @POTUS@realDonaldTrump & this amazing country. I will continue my service through August

A turbulent six months ensued. In April, Spicer was widely criticized after he stated: "We didn't use chemical weapons in World War II. You had someone as despicable as Hitler who didn't even sink to the level of using chemical weapons."

Spicer formally apologized the following day. His fiery demeanor and on-camera exchanges with reporters were lampooned on "Saturday Night Live," where he was portrayed by comedian Melissa McCarthy.