President Donald Trump replaced Chief of Staff Reince Priebus on Friday with Homeland Security Secretary John Kelly, a retired Marine Corps general.

The shift at the top of the White House hierarchy is aimed at bringing order to an administration that has been beset by infighting, as Mr. Trump seeks to notch the sort of sweeping legislative victories that he promised during the campaign but that have eluded him to this point, advisers to the president said.

“John Kelly will do a fantastic job. Gen. Kelly has been a star, done an incredible job thus far, respected by everybody,” Mr. Trump told reporters Friday.

The president told Mr. Priebus two weeks ago he was planning to bring in a new staff chief, a senior administration official said. Mr. Kelly was offered the job earlier this week and immediately accepted, the senior official said.

Mr. Trump discussed bringing in Mr. Kelly with a small group of people, the senior official said. Part of the draw, the official said, was that he believes Mr. Kelly can provide effective leadership and has the respect of the West Wing, which is staffed with aides whose ideology falls across the political spectrum.