WASHINGTON — President Donald Trump is replacing national security adviser H.R. McMaster with former U.N. Ambassador John Bolton, injecting a hawkish foreign policy voice into his administration ahead of key decisions on Iran and North Korea.

Trump tweeted Thursday that McMaster has done “an outstanding job & will always remain my friend.” He said that Bolton will take over April 9.

Bolton, a Baltimore native and resident of Bethesda, will be Trump’s third national security adviser in 14 months.

Trump has clashed with McMaster, a respected three-star general, and talk that McMaster would soon leave the administration had picked up in recent weeks. His departure follows Trump’s dramatic ouster of Secretary of State Rex Tillerson last week.

It also comes after someone at the White House leaked that Trump was urged in briefing documents not to congratulate Russian President Vladimir Putin about his recent re-election win. Trump did it anyway.

In a statement released by the White House, McMaster said he would be requesting retirement from the U.S. Army effective this summer, adding that afterward he “will leave public service.”

The White House said that McMaster’s exit had been under discussion for some time and stressed that it was not due to any one incident.

Bolton, probably the most divisive foreign policy expert ever to serve as U.N. ambassador, has served as a hawkish voice in Republican foreign policy circles for decades. He met with Trump and White House chief of staff John Kelly in early March to discuss North Korea and Iran.

Bolton has served in the Republican administrations of Ronald Reagan, George H.W. Bush and George W. Bush, and served as a Bush lawyer during the 2000 Florida recount.

A strong supporter of the Iraq war and an advocate for aggressive use of American power in foreign policy, Bolton was unable to win Senate confirmation after his nomination to the U.N. post alienated many Democrats and even some Republicans.

He resigned after serving 17 months as a Bush “recess appointment,” which allowed him to hold the job on a temporary basis without Senate confirmation.

The son of a Baltimore firefighter, Bolton grew up in a rowhouse in a working-class neighborhood behind Mount St. Joseph High School. He graduated from the McDonogh School in Owings Mills in 1966 before going on to Yale College and Yale Law School.

Bolton has remained active in Maryland Republican politics. He held fundraisers for Richard J. Douglas, a former Pentagon official and Capitol Hill lawyer who ran for the Senate in 2012 and 2015. Last fall he endorsed Amie Hoeber, the Republican consultant running for the open seat in the Maryland’s 6th Congressional District. “A terrific pick at exactly the right time,” Douglas wrote in an email Thursday evening.

“As the administration takes on critically important national security challenges [such as] North Korea, Russia, and China, John Bolton will bring uncommon seasoning to the table in diplomacy, defense, arms control, law enforcement, and geopolitics,” Douglas said.

Democrats, including Maryland Sen. Ben Cardin, criticized the decision. “John Bolton has demonstrated throughout his career he is an extremist and reckless partisan with little regard for U.S. values or allies,” said Cardin, a member of the Senate Foreign Relations Committee. “I am concerned about what advice he has given the president thus far and how he will use his official position to skew America’s national security in the future.

“The staff and Cabinet consolidation the president is engaged in is deeply troubling for our country,” Cardin added.

Tension between Trump and McMaster has grown increasingly public. Last month, Trump took issue with McMaster’s characterization of Russian meddling in the 2016 election after the national security adviser told the Munich Security Summit that interference was beyond dispute.

“General McMaster forgot to say that the results of the 2016 election were not impacted or changed by the Russians and that the only Collusion was between Russia and Crooked H, the DNC and the Dems,” Trump tweeted Feb. 17, alluding to frequent GOP allegations of impropriety by Democrats and Hillary Clinton.

Tillerson’s exit also forecast trouble for McMaster, who had aligned himself with the embattled secretary of state in seeking to soften some of Trump’s foreign policy impulses. McMaster told The New York Times last year that Trump’s unorthodox approach “has moved a lot of us out of our comfort zone, me included.”

The military strategist, who joined the administration in February 2017, has struggled to navigate a tumultuous White House. Last summer, he was the target of a far-right attack campaign as conservative groups and a website tied to former Trump adviser Steve Bannon targeted him as insufficiently supportive of Israel and not tough enough on Iran.

McMaster was brought in after Trump’s first national security adviser, Michael Flynn, was dismissed after less than a month in office. White House officials said Flynn was ousted because he did not tell top advisers, including Vice President Mike Pence, about the full extent of his contacts with Russian officials.

Baltimore Sun reporter John Fritze contributed to this article.