Sean Spicer, the White House press secretary, resigned on Friday morning, after denouncing chaos in the West Wing and telling President Trump he vehemently disagreed with the appointment of the New York financier Anthony Scaramucci as communications director.

Mr. Trump offered Mr. Scaramucci the job at 10 a.m. The president requested that Mr. Spicer stay on, but Mr. Spicer told Mr. Trump that he believed the appointment was a major mistake, according to a person with direct knowledge of the exchange.

A spokeswoman for the president, Sarah Huckabee Sanders, was elevated to press secretary. She said Mr. Trump is grateful for Mr. Spicer’s service and that the president believes Mr. Spicer will succeed going forward.

Shortly after Mr. Spicer’s resignation became public, the White House press office announced Ms. Sanders would hold the first on-air briefing since June 29.

Mr. Scaramucci acknowledged the awkwardness of Mr. Spicer’s resignation.

“This is obviously a difficult situation to be in,” Mr. Scaramucci said.

Mr. Spicer’s rumored departure has been one of the longest-running internal sagas in an administration brimming with dissension and intrigue. A former Republican National Committee spokesman and strategist, Mr. Spicer was a frequent target of the president’s ire and correctives during the first few months of the administration.