WASHINGTON -- His White House in turmoil, U.S. President Donald Trump abruptly announced late Friday he was appointing Homeland Security Secretary John Kelly to be his chief of staff, ending the tumultuous six-month tenure of Reince Priebus.

After months of speculation about Priebus' fate, Trump tweeted his decision just as he landed in Washington after a speech in New York in which he lavishly praised Kelly's performance at Homeland Security.

Priebus, the former Republican National Committee head, was the frequent target of rumours about his job security amid infighting and confusion within the White House and a long whisper campaign by Trump allies. Then, on Thursday, he was the subject of a remarkable and profane public rebuke by Trump's newly appointed White House communications director, Anthony Scaramucci.

Priebus told allies that he had offered his resignation to Trump on Thursday.

Trump's announcement on Twitter said, "I am pleased to inform you that I have just named General/Secretary John F Kelly as White House Chief of Staff. He is a Great American ... and a Great Leader. John has also done a spectacular job at Homeland Security. He has been a true star of my Administration."

He also saluted Priebus, the chief of staff he had just pushed out.

"I would like to thank Reince Priebus for his service and dedication to his country. We accomplished a lot together and I am proud of him!"

Kelly is a retired Marine four-star general. Trump had focused on him in recent days, telling those close to him that he believed military discipline was what his administration needed.

Priebus never could bring a semblance of order to the team of in-fighting rivals that populate Trump's West Wing, and questions about his future have long swirled around the office. Those questions sharply escalated this week with the arrival of Scaramucci, the hard-charging communications director who was hired over Priebus' objections.

Priebus' already tense relationship with Scaramucci took a darker turn over the past two days when the communications chief suggested in a late-night tweet that Priebus was one of the "leakers" that Trump has railed against. The New Yorker magazine published an interview Thursday in which Scaramucci called Priebus, amid an avalanche of vulgarity, a "paranoid schizophrenic."

Priebus, who hails from Wisconsin and has deep ties to House Speaker Paul Ryan, had grown increasingly isolated in the White House, as past Republican National Committee colleagues and other allies have left or been pushed out. Those who have departed include former deputy chief of staff Katie Walsh, former communications chief Mike Dubke, press secretary Sean Spicer and press aide Michael Short. Another early departure from the Trump White House was National Security Adviser Michael Flynn.

Ryan, in a statement, said Priebus "has left it all out on the field, for our party and our country." Ryan added that he looked forward to working with Kelly

Both Scaramucci and Priebus travelled to New York's Long Island with Trump on Friday for a speech in which the president highlighted efforts to crack down on the gang MS-13. Priebus took the return flight to Washington, which had to circle the runway due to a storm, his fate sealed in the tweets that were sent by the president just as he stepped off the plane.

Shortly before the president deplaned, Priebus' black SUV pulled away, leaving the rest of the motorcade, including the president's vehicle, in the distance. The president eventually emerged, umbrella in hand, and delivered a brief statement on the runway as driving rain poured.

Rep. Peter King of New York sat across from the outgoing chief of staff on Air Force One's return flight to Washington and said Priebus "kept a poker face."

Priebus did not respond to reporters' shouted questions though he later released a statement saying it was "one of the greatest honours of my life" to serve as chief of staff. He also pledged to continue to support Trump's agenda. His term ends in fewer than 200 days, the shortest tenure for any president's first White House chief of staff since the post was formally established in 1946.

From day one, Priebus' power has been limited compared with past officials with his title. In a highly unusual arrangement, Trump said at the outset that Priebus and chief strategist Steve Bannon would serve as "equal partners" in implementing his agenda.

Scaramucci was the latest top aide to be granted a direct line to Trump, and it became increasingly unclear who actually reported to Priebus. Though Priebus forged an uneasy truce with his former foe Bannon, powerful White House aides Ivanka Trump and her husband, Jared Kushner, were both supportive of Kelly's hire, according to a person familiar with the matter but not authorized to speak publicly about private discussions.

Priebus, whose departure was the latest in a string of early exits from the administration, also was blamed by some within the White House for the failure of the Republican health care plan, with some Trump allies believing that Priebus' longtime relationships with Republicans on Capitol Hill should have ensured the bill's passage.

Priebus, a political operative and attorney, is expected to look for a corporate job or possibly write a book about his experience in the centre of the Trump storm. One of the final establishment Republicans in the White House, he was a frequent target of barbs from Trump over not being an early backer of the celebrity businessman's candidacy.

As Homeland Security secretary, Kelly has taken the lead on some of Trump's most controversial policies, including his executive orders suspending the admission of refugees and temporarily barring visitors from several Muslim-majority nations. Those orders have been stripped down by courts pending a Supreme Court review this fall.

People who know Kelly told The Associated Press that he was not aware of the details of those initial orders until around the time that Trump signed them. Yet, just days after taking office, Kelly had to lead the agency as it dealt with the chaos and confusion that ensued at airports in the U.S. and around the world. He defended the orders to reporters and lawmakers and insisted that he indeed had been part of the decision-making process.

Kelly has also pushed for support for Trump's signature campaign pledge to build a wall along the southern border, though he acknowledged at his confirmation hearing that "a physical barrier in and of itself will not do the job."

Republican Sen. Lindsey Graham of South Carolina, a frequent Trump critic, said that, as Homeland Security chief, Kelly has "been very effective in engaging members of Congress and communicating a coherent message for the President."

"Secretary Kelly is one of the strongest and most natural leaders I've ever known," Graham said.

Associated Press writers Catherine Lucey, Vivian Salama, Steve Peoples and Laurie Kellman contributed reporting.

I am pleased to inform you that I have just named General/Secretary John F Kelly as White House Chief of Staff. He is a Great American.... — Donald J. Trump (@realDonaldTrump) July 28, 2017

...and a Great Leader. John has also done a spectacular job at Homeland Security. He has been a true star of my Administration — Donald J. Trump (@realDonaldTrump) July 28, 2017