Trump announced the pick Monday at his Palm Beach, Fla., club and said McMaster is "a man of tremendous talent and tremendous experience."
Sitting next to Trump for the announcement, McMaster said he was honored to take on the role and added that he looks forward to "doing everything that I can to advance and protect the interests of the American people."
The president's choice further elevates the influence of military officers in the new administration. Trump, who has no military or foreign policy experience, has shown a strong preference for putting generals in top roles. In this case, he tapped an active-duty officer for a post that's sometimes used as a counterweight to the Pentagon. McMaster, who wore his uniform for the announcement, joins Defense Secretary Jim Mattis and Homeland Security Secretary John Kelly, both retired generals, in Trump's inner circle of national security advisers.
The White House said Monday McMaster plans to remain on active military duty.
He will take on the challenge of leading a National Security Council that has not adjusted smoothly to Trump's leadership. The president suggested he does not trust holdovers from the Obama administration and complained about leaks to reporters. His decision to put his top political adviser on the senior committee of the National Security Council drew sharp criticism. On Friday, the head of the council's Western Hemisphere division was fired after he criticized Trump's policies and his inner circle of advisers.
Trump said Monday that retired Army Lt. Gen. Keith Kellogg, who had been his acting adviser, will now serve as the National Security Council chief of staff. He also said he would be asking John Bolton, a former U.S. ambassador to the United Nations, to work with them in a "somewhat different capacity."
McMaster is viewed as soldier-scholar and creative thinker. He has a doctoral degree in history from the University of North Carolina and has been heavily involved in the Army's efforts to shape its future force and its way of preparing for war. He is the director of the Army Capabilities Integration Center, a sort of military think tank, at Fort Eustis.
He also holds the title of Deputy Commanding General — Futures at TRADOC. McMaster also spent time at Fort Monroe in Hampton when it was an active Army base and hosted the TRADOC headquarters. His bio notes that he served as director of concept development and learning at TRADOC from August 2008 to May 2010.
Outside of the Army, he may be best known for his 1997 book, "Dereliction of Duty," a searing indictment of the U.S. government's mishandling of the Vietnam War and an analysis of what he called the "lies that led to Vietnam." The book earned him a reputation for being willing to speak truth to power.
McMaster commanded troops in both American wars in Iraq — in 1991, when he fought in a storied tank battle known as the Battle for 73 Easting, and again in 2005-2006 in one of the most violent periods of the insurgency that developed after the U.S.-led invasion in 2003. He is credited with using innovative approaches to countering the insurgency in the northern Iraqi city of Tal Afar when he commanded the 3rd Armored Cavalry Regiment. He later served as a special adviser to the top U.S. commander in Iraq.
McMaster was Trump's second choice to replace Flynn, who has been under FBI investigation for his contacts with Russian officials. Trump dismissed Flynn last week after revelations that the adviser had misled Vice President Mike Pence about the nature of his discussion with Russia's ambassador to the U.S. during the presidential transition. Trump said in a news conference Thursday that he was disappointed by how Flynn had treated Pence, but did not believe Flynn had done anything wrong by having the conversations.
Trump's first choice to replace Flynn, retired Vice Adm. Robert Harward, turned down the offer.
Trump announced his choice sitting between McMaster and Kellogg in a luxurious living room at the resort property. The president told reporters that Vice President Mike Pence had been involved in the process, but he did not elaborate.
Trump brought four candidates for the position to Mar-a-Lago over the weekend for in-person interviews, McMaster among them. McMaster called the appointment a "privilege."
It was not clear how closely McMaster's and Trump's views align. On Russia, McMaster appears to hold a much dimmer view than Trump of Moscow's military and political objectives in Europe.
In remarks at the Center for Strategic and International Studies in May 2016, McMaster said Russia managed to annex Crimea and intervene militarily in eastern Ukraine "at zero cost" from the international community.
McMaster said Moscow's broader goal is to "collapse the post-Cold War security, economic and political order in Europe and replace that order with something that is more sympathetic to Russian interests."
In his current role, McMaster has been studying the way Russia developed and executed its campaigns in Crimea and Ukraine, where it used what some call "hybrid warfare" — part political, part disinformation, part military.
Sen. John McCain, an increasingly vocal Trump critic, called McMaster an "outstanding" choice.
"He is a man of genuine intellect, character, and ability. He knows how to succeed," he said in a statement. "I give President Trump great credit for this decision, as well as his national security Cabinet choices."
The position of national security adviser does not require Senate confirmation.
AP National Security Writer Robert Burns contributed to this report.