Washington (CNN) National security adviser H.R. McMaster has resigned and will be replaced by former US ambassador and Fox News analyst John Bolton, President Donald Trump announced in a tweet on Thursday.

"I am pleased to announce that, effective 4/9/18, @AmbJohnBolton will be my new National Security Advisor. I am very thankful for the service of General H.R. McMaster who has done an outstanding job & will always remain my friend. There will be an official contact handover on 4/19."

"The two have been discussing this for some time. The timeline was expedited as they both felt it was important to have the new team in place, instead of constant speculation," a White House official said. "This was not related to any one moment or incident, rather it was the result of ongoing conversations between the two."

"After 34 years of service to our nation, I am requesting retirement from the U.S. Army effective this summer after which I will leave public service. Throughout my career it has been my greatest privilege to serve alongside extraordinary servicemembers and dedicated civilians," McMaster said in a statement released by the White House.

"I am thankful to President Donald J. Trump for the opportunity to serve him and our nation as national security advisor. I am grateful for the friendship and support of the members of the National Security Council who worked together to provide the President with the best options to protect and advance our national interests," the statement said.

Trump and Bolton have been discussing for weeks how he could replace McMaster. According to a source familiar with those negotiations, Bolton promised Trump "he wouldn't start any wars" if he was selected.

Shortly after the news broke, Bolton said on Fox News that he wasn't expecting an announcement to be made Thursday afternoon.

Asked when he was offered the job, Bolton said "it came to a conclusion this afternoon."

CNN also confirmed that Bolton met with Trump Thursday.

White House officials told CNN that they were surprised by Trump's acceleration of the announcement, saying it was unexpected, and one official added that the choice of Bolton was expected to be part of a bigger release.

An official said the blowback over Trump's call to Russian President Vladimir Putin on his reelection sped up the announcement. One official also said Trump was eager to get ahead of other news.

Bolton said in the Fox News interview that he will be going through a transition period -- which will include working with McMaster -- before taking over on April 9.

A controversial pick

Bolton's hard edged, hawkish views on issues like North Korea , Iraq and Syria make him a controversial pick to become the next national security adviser -- particularly considering that talks with North Korea may soon be possible.

Several sources have told CNN that Defense Secretary James Mattis opposed the pick and tried to block Bolton from getting the job.

Bolton said on Fox News Thursday that he and Mattis have never met.

The Pentagon said it does not have an official comment to make at this time.

Megan Stifel, a former NSC staffer during the Obama administration responded to the news by simply tweeting: "Now I'm concerned."

Early in the Trump administration Bolton -- a stalwart of several Republican administrations -- was considered as a possible secretary of state and since then has made visits to the West Wing every few months to discuss foreign policy and national security.

A source familiar with those meetings said the two have spent more time recently getting to know each other, discussing Bolton's views and getting a better sense of each other.

Initially there was a concern that Bolton had not made it clear enough that, if tapped, he would "absolutely go along with Trump," a source close to Bolton told CNN, adding that during their last meeting he went over and above to make clear he will do exactly what Trump wants.

Bolton said on Fox News that he has been a prolific speaker and writer for years in Washington, but said that his past comments are now "behind me" and what matters is "what the President says."

After the two met in the Oval Office last week, a source close to the President said: "Trump has always wanted Bolton."

Despite once bemoaning Bolton's thick mustache as unbefitting of a senior White House official, Trump has now determined he can look past it, one person familiar with his thinking said.

McMaster has been on thin ice

Amid speculation about McMaster's fate CNN has reported that the three-star general has been in discussions with the Hoover Institution. As recently as March 8, the White House was denying reports that McMaster was on his way out, with spokeswoman Sarah Sanders declaring on "Fox & Friends" that "General McMaster's not going anywhere."

CNN reported earlier this month that the Pentagon has also been considering options that would allow the President to potentially move McMaster out of his current role and back into the military, according to half a dozen defense and administration officials.

And the Pentagon had been quietly looking to see if there is a four-star military job suited for McMaster, these officials said.

But McMaster's announced retirement from the military this summer would mean he wouldn't receive his fourth star.

National Security Council spokesman Michael Anton had dismissed reports of McMaster's departure, telling CNN on March 1 that Trump had dismissed stories of McMaster's ouster as "'fake news,' and told McMaster that he is doing a great job."

Several sources told CNN that the decision came after months of personal tension between McMaster and Trump.

Trump has privately expressed irritation with McMaster stemming from differences in "personality and style," a senior Republican source said.

The two have never gotten along, and Trump continues to chafe at McMaster's demeanor when he briefs him, feeling that he is gruff and condescending, according to a source who is familiar with his thinking.

Sources with knowledge of McMaster's standing in the White House had repeatedly said that he was on thin ice.

That building frustration was again on display this week after after it quickly leaked that Trump had been directly instructed by his national security advisers not to congratulate Russian President Vladimir Putin on his recent election victory.

Trump was furious -- asking White House aides and allies if they thought it was "a McMaster person" who had leaked it to the press, a source familiar with how things unfolded said.

There was discussion in the West Wing about replacing him last fall, but he ultimately survived because officials, including the President himself, were skeptical about the optics of appointing a third national security adviser in less than a year, several sources told CNN. Trump's first national security adviser, Michael Flynn, resigned amid controversy over his contact with Russian officials within a month of taking the job.

McMaster was also retained at the time because of the White House's challenge attracting top talent for jobs in the administration due to Trump's "blacklist" of individuals who have criticized the President, his personality and the Russia investigation, according to a senior Republican source.