WASHINGTON — His White House in turmoil, 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, President 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.

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….

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

Homeland Security Seretary John Kelly said he thinks President Trump “will be insistent” that lawmakers include money for a border wall in the budget.

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

President 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. President 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 President 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 President 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 traveled to New York’s Long Island with President 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 honors of my life” to serve as chief of staff. He also pledged to continue to support President 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, President 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 President 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 President 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 center of the President Trump storm. One of the final establishment Republicans in the White House, he was a frequent target of barbs from President 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 President 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 President 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 President 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 President 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.

NATIONAL HARBOR, MD – MARCH 04: Chairman of the Republican National Committee Reince Priebus participates in a discussion during CPAC 2016 March 4, 2016 in National Harbor, Maryland. The American Conservative Union hosted its annual Conservative Political Action Conference to discuss conservative issues. (Photo by Alex Wong/Getty Images)

Sen. Ron Johnson issued the following statement on the Priebus ouster:

“Reince Priebus is a good friend. I thank him for his service and wish him the best of luck going forward. Secretary Kelly is an outstanding leader who has served his country honorably and I know he will do an excellent job at the White House. I look forward to working with the administration as they choose a new leader for the Department of Homeland Security.”

(2/2) Disappointing News- @realDonaldTrump has new COS. We're proud of you @Reince! You accomplished a lot, and did your state proud! LYB