WASHINGTON — Sean Spicer, the White House press secretary, resigned Friday after telling President Trump he vehemently disagreed with his appointment of Anthony Scaramucci, a New York financier, as his new communications director.

After offering Mr. Scaramucci the job on Friday morning, Mr. Trump asked Mr. Spicer to stay on as press secretary, reporting to Mr. Scaramucci. But Mr. Spicer rejected the offer, expressing his belief that Mr. Scaramucci’s hiring would add to the confusion and uncertainty already engulfing the White House, according to two people with direct knowledge of the exchange.

Mr. Spicer’s top deputy, Sarah Huckabee Sanders, will serve as press secretary instead.

The long-anticipated resignation rattled an administration already reeling from the most trying two-week stretch of Mr. Trump’s presidency. The president’s health care effort foundered in the Senate last week, and next week promises no respite, with his son Donald Trump Jr. and son-in-law, Jared Kushner, due to testify before Congress on questions about their contacts with Russia.

If the moves amounted to a kind of organizational reset, it was not part of a pivot or grand redesign. The president, according to a dozen people familiar with the situation, meant to upgrade, not overhaul, his existing staff with the addition of a smooth-talking, Long Island-bred former hedge fund manager who is currently the senior vice president and chief strategy officer at the Export-Import Bank, which he joined just last month. His rapport with the president establishes a new power center in a building already bristling with rivalry.