WASHINGTON (AP) — 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, Trump tweeted his decision 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, has been a frequent target of rumors 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 said he had offered his resignation on Thursday and the president accepted.

“I think the president wanted to go a different direction,” Priebus told CNN just hours after his exit was announced. He added that he agreed the White House might well benefit from “a reset,” and he said, “I’m always going to be a Trump fan. I’m on Team Trump.”

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 loved the general’s star power and 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.”