US Defense Secretary James Mattis finally announced his long-anticipated resignation to allow President Donald Trump to have a defense chief whose views are more aligned with the US president, he said in his resignation letter Thursday.

Mattis, a retired Marine Corps general who was known as a stabilizing force in President Trump's cabinet, will leave his job at the end of February, Trump said in a tweet on Thursday.

“General Jim Mattis will be retiring, with distinction, at the end of February, after having served my Administration as Secretary of Defense for the past two years,” Trump tweeted.

....equipment. General Mattis was a great help to me in getting allies and other countries to pay their share of military obligations. A new Secretary of Defense will be named shortly. I greatly thank Jim for his service! — Donald J. Trump (@realDonaldTrump) December 20, 2018

Trump also announced he would nominate a successor to Mattis shortly.

Despite Trump’s talk of retirement, Mattis said in his resignation letter that he was stepping down so Trump could have a defense chief whose views align more closely with his own.

JUST IN: "Because you have the right to have a Secretary of Defense whose views are better aligned with yours on these and other subjects, I believe it is right for me to step down from my position," Sec. Mattis says in resignation letter to Pres. Trump. https://t.co/nuTUUJQ45P pic.twitter.com/FMGBbPhVJW — ABC News (@ABC) December 20, 2018

His departure had been anticipated since Trump announced on Wednesday that he was withdrawing US troops from Syria despite opposition from US allies and top US military officials.

Mattis joins a long list of former Trump administration senior figures who have either quit or been removed, some unceremoniously like Secretary of State Rex Tillerson who Trump fired via Twitter in March.

Trump's White House has had the highest turnover of senior-level staff of the past five presidents, according to the Brookings Institution think tank.

Speculation that Mattis might not last long in his post grew in October when Trump said in a CBS interview that the general was "sort of a Democrat" and might be leaving.

During an interview with CBS, the president was asked if Mattis – with whom he has at times reportedly had a strained relationship – was going to leave.

“I don’t know. He hasn’t told me that,” he said. “I have a very good relationship with him. I had lunch with him two days ago. I have a very good relationship with him. It could be that he is. I think he’s sort of a Democrat, if you want to know the truth.”

He added, “General Mattis is a good guy. We get along very well. He may leave. I mean, at some point, everybody leaves. Everybody. People leave. That’s Washington.”

However, Trump said in the same interview there were some people in his administration he is “not thrilled with”.

Speculation intensified in September with the publication of Bob Woodward’s Fear: Trump in the White House, which claimed the former military officer had described Trump as an idiot and told colleagues the president “acted like – and had the understanding of – a fifth- or sixth-grader”.

Read more:

Woodward quotes one scene in which the president reportedly told the defense secretary to “kill” Bashar al-Assad after the Syrian leader was accused of using chemical weapons in an alleged attack on civilians in April 2017.

The book said Mattis told the president that he would get right on it. But after hanging up the phone, he told an aide, “We’re not going to do any of that. We’re going to be much more measured.”