WASHINGTON — President Trump frequently referred to John F. Kelly as one of “my generals,” the three senior military leaders he recruited for his team. On Friday, Mr. Trump decided to see whether Mr. Kelly, a retired four-star Marine Corps general, could impose a new sense of discipline on an unruly and chaotic West Wing.

Mr. Kelly, who became a star in Mr. Trump’s eyes for overseeing immigration policy as secretary of homeland security, will become the president’s second chief of staff. He replaces Reince Priebus, the establishment Republican who never completely meshed with Mr. Trump. Mr. Priebus was ousted after a nasty public feud with Anthony Scaramucci, the new White House communications director.

The square-jawed Mr. Kelly, the first general to hold the chief of staff position since Alexander M. Haig during the Nixon administration, will be an imposing and strait-laced figure in a West Wing filled with constantly warring aides and advisers, most of whom came to Washington with virtually no experience in federal government before Mr. Trump’s victory last year.

“John has also done a spectacular job at Homeland Security,” Mr. Trump wrote on Twitter, calling Mr. Kelly a “great American” and saying he had been a “true star of my Administration.”