When White House officials learned last week that The Daily Mail would publish an article about allegations by the ex-wives, Hope Hicks, the communications director, who had been dating Mr. Porter, and Sarah Huckabee Sanders, the press secretary, approached Mr. Kelly about a statement in support of him, according to two people briefed on the events. Mr. Kelly, who had been on Capitol Hill much of the day, agreed to have a statement issued in his name describing the charges as “vile.”

Nonetheless, the people briefed on the discussions said, Mr. Kelly told Mr. Porter at some point later that evening that he needed to resign. Mr. Porter agreed. It was not issued as a clear order, but it was understood that Mr. Porter would go, according to the two people briefed on the discussions. Mr. Porter has offered a different version of events, telling associates that he was initially urged to stay on and fight, including by Mr. Kelly.

Either way, Mr. Porter arrived at work on Wednesday morning and told Mr. Kelly that he was reconsidering stepping down, according to the two people briefed. Mr. Kelly again said Mr. Porter needed to leave, the people said. Mr. Porter agreed and told colleagues that he planned to resign without setting a departure date so he could help with the transition. He maintained to colleagues that his ex-wives were making up their stories of abuse and that while he was flawed, he was not physically abusive.

The official line remained that Mr. Porter had made the choice to leave on his own and was not asked. Ms. Sanders, whose briefing materials take hours to prepare and whose official statements are agreed to in advance by senior aides, said from the briefing room lectern that Mr. Kelly and Mr. Trump still had full confidence in Mr. Porter.

At various points, officials have said it was the publication of the photographs that changed their calculation. “The photographs took everybody by surprise,” Mr. Mulvaney said.

Mr. Kelly was persuaded to issue a second statement expressing shock, and White House officials made clear that Mr. Porter would be gone the next day. But Thursday morning, Mr. Porter was still in his office, clearing out his things, and had to be nudged to leave.

Mr. Porter has told associates that he had informed White House officials last year that he had two ex-wives who, he said, had manufactured claims about him. Other officials said he described messy and complicated divorces, but offered no specific details. Two West Wing officials said Mr. Porter had offered conflicting portraits of his marriages. One official said he at first discussed one divorce, and then two. Initially, he said that he had been verbally abusive but that his wives had been too.