The White House was engulfed in chaos Friday as officials scrambled to contain the fallout from its management of domestic violence allegations against staff secretary Rob Porter, even as President Trump lavished praise on the now-departed senior aide and suggested he may be innocent.

And amid the tumult, the man whose mission had been to enforce order in the West Wing, Chief of Staff John F. Kelly, was focused instead on a more personal goal — to save his job — as Trump seriously sounded out confidants about possible replacements.

Trump and Kelly have had a series of conversations in recent days that two White House officials described as “very turbulent.” The president is upset with his top aide — as well as with White House Communications Director Hope Hicks — for not being more transparent with him about the allegations against Porter and for their botched public relations push to defend him, according to four officials.

Kelly and his loyal deputies have been “frantically trying to stop the bleeding,” according to one West Wing staffer, who, like the others interviewed, spoke on the condition of anonymity to candidly describe the chaos. ­Kelly’s efforts at damage control included instructing senior aides at a Friday morning meeting to communicate that he had taken action to remove Porter within 40 minutes of learning that abuse allegations from both of Porter’s ex-wives were credible, according to two senior officials. That account contradicts the administration’s public statements and other private accounts.

In a conversation with Trump, Kelly said he would be willing to resign if that would improve the situation, but he made the offer casually and did not submit a letter of resignation or take formal action, according to two White House officials.

Porter left his job Thursday after both of his ex-wives publicly detailed episodes of alleged physical and verbal abuse. White House officials have offered contradictory accounts of whether he resigned or was terminated. Porter has denied the allegations.

On Friday, the White House announced that David Sorensen, a speechwriter who worked under senior policy adviser Stephen Miller, has resigned after his former wife claimed that he was violent and emotionally abusive.

Aides described a resulting level of dysfunction not experienced behind the scenes at the White House since the early months of Trump’s presidency. Dormant ­rivalries have come alive, with suspicions swirling about some of the most senior officials and the roles they apparently played in protecting Porter.

“People are using it to their advantage,” one West Wing aide said. “If you hate Kelly, this is your moment. Hope’s enemies are using it to go after her.”

Mercedes Schlapp, the director of strategic communications, who is responsible for long-term planning, advised some lower-level press staffers to deal with her because Hicks was distracted by the Porter situation — a move that one White House official said was interpreted as an encroachment on Hicks’s turf.

Schlapp called this characterization “completely false,” saying in a statement, “Hope and I work hand-in-hand.”

Hicks, who had been dating Porter and played an integral role in orchestrating the initial White House responses defending him after the first allegations were reported Tuesday, has been the target of some of the internal blame.

Having worked as Trump’s top communications adviser for three years, Hicks is considered almost a member of the family. She is arguably the president’s closest personal confidante in the White House, and their relationship has shielded her during previous ­internal battles. But officials said the Porter situation has exposed her vulnerabilities.

Officials described Kelly as more endangered than Hicks, adding that the chief of staff had lost the trust and confidence of some on the senior staff. But advisers said they saw no evidence that Trump was preparing to oust Kelly imminently; one of them suggested the president may try to publicly torment him for a while, which is the style of punishment he has given other aides when he is unsatisfied with their performances.

“The president has complete confidence in General Kelly and Hope Hicks,” White House spokesman Hogan Gidley said in a statement.

Trump is mercurial and impulsive by nature, however. His advisers cautioned that he could decide on a moment’s notice to let Kelly go — as he did with Kelly’s predecessor, Reince Priebus, who spent a Friday in July traveling with Trump only to be unceremoniously terminated in a presidential tweet that was sent as Priebus was descending the steps from Air Force One onto a rain-soaked tarmac at Joint Base Andrews near Washington.

In private conversations in recent days, Trump has sounded out advisers, both inside and outside the administration, about removing Kelly, who has been on the job for 6½ months. He has repeatedly floated the possibility of hiring House Majority Leader Kevin McCarthy (R-Calif.) or Office of Management and Budget director Mick Mulvaney as chief of staff, according to people who have discussed the matter with him.

These people said Trump is casting a wide net that also includes Gary Cohn, director of the National Economic Council. The former Goldman Sachs executive, who had been one of Trump’s favorite staffers in the early days, would be an intriguing choice considering his falling out with the president last summer after Cohn’s harsh public criticism of Trump’s response to the deadly white supremacist rally in Charlottesville.

Cohn has started making his way back into Trump’s good graces, having played an integral role in last December’s passage of tax cuts and the president’s visit to the World Economic Forum in Davos, Switzerland.

Another potential candidate for chief of staff is businessman Thomas J. Barrack Jr., a friend and contemporary of Trump’s who chaired his inauguration committee. Barrack has long been rumored for a job in the administration, but he has told the president at various moments that he would not want to serve in the White House because of his complicated financial circumstances, according to people familiar with their conversations.

Kelly spent much of Friday scrambling to preserve his credibility inside the White House. In a morning staff meeting, he told senior aides to tell lower-level staffers throughout the White House that he had taken action within 40 minutes of learning that abuse allegations from both of Porter’s ex-wives were credible, according to two senior officials. He also sought to assure attendees that he cares about domestic violence, the officials said.

“He told the staff he took immediate and direct action,” one of the officials said.

Since that account contradicts the Trump administration’s previous accounts, some staffers left the meeting believing Kelly had asked them to lie, according to the two senior officials.

The instructions by Kelly early Friday mark the latest twist in the White House’s shifting accounts of the Porter episode. On Tuesday night, after the abuse allegations against Porter were made public by British newspaper the Daily Mail, Kelly said in a statement: “Rob Porter is a man of true integrity and honor, and I can’t say enough good things about him. He is a friend, a confidante and a trusted professional. I am proud to serve alongside him.”

On Wednesday morning, after photographs were posted on Twitter overnight by an Intercept reporter showing one of Porter’s ex-wives with a black eye, Kelly privately stood by Porter and urged him to stay in the job, White House officials said at the time.

Porter issued a statement midday Wednesday denying the allegations but announcing his departure. That afternoon, White House press secretary Sarah Huckabee Sanders said Porter still had the White House’s support and that the decision to resign was his own. “I can tell you that Rob has been effective in his role as staff secretary, and the president and chief of staff have had full confidence and trust in his abilities and his performance,” Sanders told reporters.

Wednesday night, Kelly issued a new statement condemning domestic violence and saying he was “shocked by the new allegations” against Porter. He also said he stood by his “previous comments of the Rob Porter that I have come to know since becoming Chief of Staff, and believe every individual deserves the right to defend their reputation.”

By Thursday afternoon, White House spokesman Raj Shah said Porter had been “terminated” on Wednesday and had cleaned out his desk.

Trump — who has told confidants he was angry that the Porter saga was national news for several straight days — spoke out on the matter for the first time Friday. After summoning reporters into the Oval Office, Trump said this was a “tough time” for Porter and “we absolutely wish him well.” The president said nothing about his ex-wives’ allegations, nor did he broadly condemn domestic violence.

“He did a very good job when he was in the White House, and we hope he has a wonderful career, and he will have a great career ahead of him,” Trump said. “But it was very sad when we heard about it, and certainly he’s also very sad now. He also, as you probably know, says he’s innocent, and I think you have to remember that.”

By contrast, Vice President Pence, who is traveling in South Korea, strongly condemned domestic violence and vowed to personally investigate the Porter matter when he returns to Washington and “share my counsel with the president directly.”

“There is no tolerance in this White House and no place in America for domestic abuse,” Pence said in an interview Friday with NBC News. “That being said, I think the White House has acknowledged that they could have handled it better.”

Trump has not spoken publicly about Kelly or addressed the failings of his administration to deal with Porter’s domestic violence allegations. White House Counsel Donald McGahn first learned that Porter’s ex-wives were prepared to make damaging statements about him in January 2017, and then was told at least three other times about the allegations, including by the FBI, which learned of them during its background check of Porter for a security clearance.

The White House sought Friday to project an air of normalcy, announcing a slew of new personnel appointments and promotions, including the elevation of John DeStefano to counselor to the president, who had been the director of presidential personnel and now will also oversee the offices of political affairs and public liaison.

Also promoted was Zachary ­Fuentes, a Kelly aide, who will become senior adviser to the chief of staff. And James Carroll, who had been a deputy chief of staff, is moving to the Office of National Drug Control Policy as its acting director.

Carol D. Leonnig contributed to this report.