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.”