Raised voices could be heard through the thick door to the Oval Office as John Kelly then Secretary of Homeland Security offered some tough talk to President Donald Trump.

Mr. Kelly, a whip-cracking retired general who was sworn in as White House chief of staff on July 31, 2017, had demanded to speak to the President alone after Mr. Trump complained loudly that the U.S. was admitting travellers from countries he viewed as high risk.

Mr. Kelly first tried to explain to Mr. Trump that the admissions were standard some people had legitimate reasons to visit the country but the President insisted that it was making him look bad, according to an administration official familiar with the exchange about a month ago.

Mr. Kelly then demanded that other advisers leave the room so he could speak to the President frankly. Mr. Trump refused at first, but agreed when Mr. Kelly insisted.

It was an early indication that Mr. Kelly, a decorated retired Marine general who served three tours in Iraq, is not afraid to stand up to his commander-in-chief.

Tapped to bring order to a chaotic West Wing, Mr. Kelly began to make his mark immediately on July 31, 2017, ousting newly appointed communications director Anthony Scaramucci and revising a dysfunctional command structure that has bred warring factions. From now on, said White House Press Secretary Sarah Huckabee Sanders, all senior staffers including the President’s son-in-law Jared Kushner and chief strategist Steve Bannon will report to Mr. Kelly instead of the President.

Mr. Kelly “will bring new structure, discipline and strength” to the White House, Ms. Sanders said.

“It definitely has the fingerprints of a new sheriff in town,” said Blain Rethmeier, who guided Mr. Kelly through the Senate confirmation process for the Homeland Security post. Mr. Rethmeier said that what stood out about Mr. Kelly during the time they worked together was the way Mr. Kelly commanded respect from everyone he encountered and the way he respected others.

Mr. Kelly drew praise from lawmakers of both parties on August 1, 2017.

Senator Lindsey Graham expressed confidence that Mr. Kelly can help restore order, saying on NBC’s “Today” show that “the Marines have landed at the White House. They have a beachhead.”

And Senator Dick Durbin of Illinois told CNN that Mr. Kelly “is in a position where he can stabilise this White House, that’s good for this country. The President has to be part of that.”

Jason Miller, a senior communications adviser during the Trump presidential campaign, predicted on CNN that Mr. Kelly’s next move will be to put people in place that will help the President. He suggested Mr. Kelly should convince ousted Press Secretary Sean Spicer to stay on, at least through the tax overhaul effort.

Mr. Kelly fostered a reputation as an outspoken commander who didn’t shy away from unpopular opinions during his military career. Mr. Rethmeier said that Mr. Kelly also respects authority deeply “and that’s something that Trump sort of smells out, if you respect him or not”.

“If he disagrees with you, he’ll disagree respectfully,” Mr. Rethmeier said.

It was a point Mr. Kelly made clear during his confirmation hearing in January. “I have never had a problem speaking truth to power, and I firmly believe that those in power deserve full candour and my honest assessment and recommendations. I also value people that work for me speaking truth to power,” he said.

In April, Mr. Kelly bluntly challenged members of Congress critical of the Trump administration’s aggressive approach to immigration enforcement to either change the laws or “shut up”.

But after being confirmed as part of Mr. Trump’s Cabinet, Mr. Kelly also tried to moderate some of the President’s hardline positions, even as he publicly defended them.

Mr. Kelly and Defence Secretary Jim Mattis, another retired general, were also said to have been deeply frustrated with the rollout of Mr. Trump’s refugee and immigration ban, and made clear to associates that they were not involved in drafting it or aware of its details around the time that Mr. Trump signed the original order. Both moved swiftly to address gaps in the measure, with Mr. Mattis asking that Iraqis who helped U.S. troops be exempt and Mr. Kelly clarifying that green-card holders would not be affected.

Nonetheless, Mr. Kelly launched a particularly robust defence of the order to lawmakers and reporters, which was welcomed by the White House.

Mr. Mattis and Mr. Kelly also agreed in the earliest weeks of Mr. Trump’s presidency that one of them should remain in the United States at all times to keep tabs on the orders rapidly emerging from the White House, according to a person familiar with the discussions. The official insisted on anonymity in order to discuss the administration’s internal dynamics.

Senator Bob Corker said on July 31, 2017 that he discussed Mr. Kelly’s appointment with Mr. Trump and hopes Mr. Kelly “will do everything possible to bring the appropriate discipline and focus that needs to be at the White House there”.

“I hope that Gen. Kelly will absolutely, forcefully clean the place up,” Mr. Corker said. “And anybody who’s been a violator, who’s been a part of public backbiting, part of undermining, who’s been part of feathering their own nest at other people’s expense, I hope they’ll all be gone.”

David B. Cohen, a University of Akron political science professor writing a book on Chiefs of Staff, applauded Mr. Kelly for doing “things that should have been done on Day One of Reince Priebus’s tenure.” He said Mr. Scaramucci’s removal sent a clear message “that going off-script and being undisciplined” would no longer be tolerated at the White House.

But Mr. Cohen wondered how long Trump would go before undermining Mr. Kelly.

“President Trump is his own worst enemy,” he said. “He instinctively likes to be his own chief of staff and he’s a pretty awful one. Will he be able to resist messing with the system once John Kelly cleans everything up? Will he listen to his chief of staff when Kelly has to tell Trump, ‘No,’” he asked.

“I’m not sure President Trump is wired to be able to listen to that type of criticism,” he said.