McMaster's exit is the latest in a string of high-profile departures from the White House that started with national security advisor Michael Flynn and has also included chief of staff Reince Priebus, chief strategist Steve Bannon, economic advisor Gary Cohn and secretary of state Rex Tillerson.
"I am pleased to announce that, effective 4/9/18, @AmbJohnBolton will be my new National Security Advisor," Trump said in a tweet.
"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/9."
McMaster had been expected to leave later this year, so his exit was little surprise. But Bolton's nomination has stunned much of Washington.
A vocal advocate of the Iraq war, he has also championed preemptive strikes against North Korea and war with Iran -- making him an outlier even among Republicans.
His appointment had been fiercely opposed by many within Trump's inner circle, most notably the coterie of military officers who have experienced the brutality of war first hand.
Bolton will now have a central role in crafting US foreign policy, by framing Trump's decisions on defense and security.
His ideological approach to foreign policy matches neatly with Trump's tough-talking rhetoric, although the two have not always agreed on the use of force.
Unlike the secretaries of state or defense, the national security advisor works directly for the president and does not need to be confirmed by the Senate in order to take up his post.
His arrival comes as Trump faces a high stakes meeting with North Korean leader Kim Jong Un and weighs the future of a deal to curb Iran's nuclear weapons, which now appears to be in grave peril.
McMaster, a three-star army general, had been expected to move out of the White House and into a four-star position.
Instead he will retire from public life.
"After thirty-four years of service to our nation, I am requesting retirement from the US Army effective this summer after which I will leave public service," he said in a statement.
"Throughout my career it has been my greatest privilege to serve alongside extraordinary service members and dedicated civilians."
McMaster had been brought in to replace Flynn, Trump's first national security advisor who has since admitted to lying to the special counsel Robert Mueller and has turned state witness.
Bolton's appointment brought sharply different reactions, along the predictable party lines.
Trump loyalist, Congressman Lee Zeldin, applauded the appointment and described Bolton as "ridiculously knowledgeable."
"Leaks from NSC will end. Obama holdovers will be gone & team, chemistry & work product will all get ramped up. Very underrated, amazing American. Extraordinarily talented pick," he tweeted.
Democratic Senator Edward Markey described the appointment as "a grave danger to the American people and a clear message from President Trump that he is gearing up for military conflict."
Get the latest election news, live updates and election schedule for Lok Sabha Elections 2019 on ndtv.com/elections. Like us on Facebook or follow us on Twitter and Instagram for updates from each of the 543 parliamentary seats for the 2019 Indian general elections.