Spicer quit in protest over the hiring of a new White House communications director, New York financier Anthony Scaramucci, objecting to what Spicer considered his lack of qualifications and to the direction of the press operation, according to people familiar with the situation.
RELATED: Sean Spicer's Hitler, 'Holocaust center' comments raise eyebrows
As his first act on the job, Scaramucci announced that Sarah Huckabee Sanders would be the new press secretary. She had been Spicer's deputy.
The shake-up on the communications team comes as Trump is suffering from dismal approval ratings and struggling to advance his agenda. The president has been frustrated by all the attention devoted to investigations of allegations of his election campaign's connections to Russia.
Trump, who watches the press briefings closely and believes he is his own best spokesman, in a statement saluted Spicer's "great ratings" on TV and said he was "grateful for Sean's work on behalf of my administration and the American people."
TIMELINE: Sean Spicer's most memorable moments as White House press secretary
Scaramucci, in a briefing room appearance after his appointment was made official, flashed the television skills that Trump has long valued: He praised Trump's political instincts and competitiveness, cracked a few self-deprecating jokes and battled with reporters who categorized the West Wing as dysfunctional, saying "there is a disconnect" between the media and the way the public sees the president.
Spicer said during a brief phone conversation with The Associated Press that he felt it would be best for Scaramucci to build his own operation "and chart a new way forward." He tweeted that it had been an "honor" and "privilege" to serve Trump and that he would remain in his post through August.
His decision to quit was sudden and took advisers inside and outside the White House by surprise, according to the people with knowledge of the decision. They spoke on condition of anonymity because they were not authorized to discuss the personnel matter publicly.
Spicer's daily press briefings had become must-watch television until recent weeks when he took on a more behind-the-scenes role. Sanders had largely taken over the briefings, turning them into off-camera events.
Scaramucci did not commit to putting the briefings back on camera full-time. He also made clear that he would continue the West Wing's plan to push back against media reports it doesn't like - and would do a better job of selling its victories.
"The president is a winner. And we're going to do a lot of winning," Scaramucci said.
Spicer had long sought the strategic communications job for himself and had been managing that role along with his press secretary duties for nearly two months.
RELATED: Gronkowski crashes White House press briefing
Spicer spent several years leading communications at the Republican National Committee before helping Trump's campaign in the general election. He is close to White House chief of staff Reince Priebus, the former RNC chair, and several of the lower-ranking aides in the White House communications shop.
Priebus told The Associated Press that he supports Scaramucci "100 percent," despite reportedly trying to prevent the financier from getting multiple administration positions.
"We go back a long, long way and are very good friends," Priebus said of Scaramucci. "All good here."
Spicer also complimented Scaramucci, a New York financier and frequent defender of the president who was a staple at Trump Tower during the president's transition, saying "It'll be great, he's a tough guy."
Scaramucci is expected to play a visible role as one of Trump's defenders on television. But Spicer and other officials questioned his hiring as communications director ahead of the president's push to overhaul the tax system and other policy issues.
Spicer and other press staffers had been feeling that they finally had the press shop operating effectively, aside from matters related to the Russia investigation, said one of the people familiar with the situation.
Scaramucci's hire was a surprise. He had been told by the administration that he would be nominated as U.S. ambassador to the Organization for Economic Cooperation and Development, an intergovernmental economic organization that includes the world's better-off countries.
Spicer's tenure got off to a rocky start. On Trump's first full day in office, he lambasted journalists over coverage of the crowd size at the inauguration and stormed out of the briefing room without answering questions.
Spicer, who often displayed a fiery demeanor in tense on-camera exchanges with reporters, became part of culture in the way few people in his job have, particularly through an indelible impersonation by Melissa McCarthy on NBC's "Saturday Night Live."
She portrayed Spicer as a hostile figure who tore through the briefing room on a portable podium, willing to attack the press.
A Roman Catholic, Spicer was dealt a blow when Trump excluded him from a group of White House staffers and Trump family members who got to meet Pope Francis when Trump visited the Vatican during his first foreign trip in May.
Spicer remained loyal to Trump but frequently battled perceptions that he was not plugged in to what the president was thinking, and had to worry that Trump was watching and critiquing his performance from the Oval Office.
The resignation comes a day after Mark Corallo, the spokesman for the president's outside legal team, left his post. And in a separate move, former White House aide Katie Walsh is returning to the RNC, spokesman Ryan Mahoney said. Walsh will serve as an adviser on data and digital issues, and the appointment is unrelated to the White House personnel changes, he said.
Report a typo to the ABC13 staff