McMaster was brought in to stabilise a turbulent foreign policy operation after Trump's first national security adviser, Michael Flynn, was dismissed because he did not tell White House officials, including Vice President Mike Pence, about the full extent of his contacts with Russian officials.
McMaster has done "an outstanding job & will always remain my friend", Trump tweeted.
Bolton, who has advocated using military force against Iran and North Korea and has taken a hard line against Russia, will take over April 9, Trump said. The 69-year-old has long been a polarising figure in Washington foreign policy circles, and is Trump's third national security adviser in 14 months.
Probably the most divisive foreign policy expert ever to serve as UN ambassador, Bolton has served as a hawkish voice in Republican foreign policy circles for decades. He met Trump and White House chief of staff John Kelly early this month to discuss North Korea and Iran.
McMaster's resignation is the latest in a long line of staff to leave the White House under Trump's presidency. Here are some of the notable ones:
March 22, 2018: National security adviser, H.R. McMaster
March 16, 2018: Deputy Director of the FBI, Andrew McCabe
March 13, 2018: Secretary of State, Rex Tillerson
March 12, 2018: President Trump's personal assistant, John McEntee
March 6, 2018: Head of the National Economic Council Gary Cohn
February 28, 2018: Communications director Hope Hicks
February 27, 2018: Deputy communications director Josh Raffel
February 7, 2018: Staff secretary Ron Porter
December 13, 2017: Communications director for the White House Office of Public Liaison Omarosa Manigault Newman
December 8, 2017: Deputy national security adviser Dina Powell
September 29, 2017: Health and Human Services Secretary Tom Price
August 25, 2017: National security aide Sebastian Gorka
August 18, 2017: Chief strategist Steve Bannon
July 31, 2017: Communications director Anthony Scaramucci
July 28, 2017: Chief of staff Reince Priebus
July 21, 2017: Press secretary Sean Spicer
May 30, 2017: Communications director Michael Dubke
May 9, 2017: FBI Director James Comey
February 13 2017: National security adviser Michael Flynn
-AP