More than any other officer of his generation, Lt. Gen. H.R. McMaster's military career has been defined by a willingness to dissent - often forcefully.

In "Dereliction of Duty," the book he wrote in the 1990s, McMaster blasted the nation's top generals for their unwillingness to tell a domineering president that his war strategy in Vietnam could not work.

More than a decade later as the commander of a 5,000-soldier regiment in Iraq, McMaster essentially ignored the U.S. military's prevailing plan for stabilizing the country, which he concluded was failing badly.

On Monday President Donald Trump chose McMaster as his national security adviser, replacing the ousted Michael Flynn. McMaster's surprising rise has his supporters and critics asking the same question: How will a soldier known for his sharp mind and even sharper opinions get along with a president who does not like being told that he is wrong?

"I have tremendous respect for H.R. as a military professional," Stephen Biddle, a political scientist who has worked closely with the U.S. military in Iraq and Afghanistan. "Whether he can be as effective and candid as we all hope is the big question."

In his many successes and his most notable failure - leading an anti-corruption task force in Afghanistan - McMaster has displayed the same traits: a fierce intellect, dogged determination and a penchant for conflict that has produced loyal supporters and, in some cases, determined foes.

McMaster comes to the job leading the White House's National Security Council with some significant disadvantages relative to his predecessors. The most effective national security advisers have close personal relationships with the president. It's not clear whether McMaster had even met Trump before interviewing for the job.

McMaster, a three-star general, will be coordinating and helping to oversee a Cabinet that includes retired Marine Gens. Jim Mattis and John Kelly, both of whom outranked him when they were in uniform and could view him as a subordinate or someone they can bypass.

Finally, McMaster's decision to stay on active duty even as he serves in the Trump White House could make it harder for him to disagree forcefully with the president or other senior administration officials. "It is a lot easier to say 'Screw this job' or 'I am not doing that' as a civilian," said a friend of McMaster, who spoke on the condition of anonymity to be frank. "It is the ethos of the military to do what you are told whether or not you like the mission or the chain of command."

The ethos of uncritically following orders is one that has never come easily to McMaster. McMaster wrote about the Vietnam War at a moment when most of the U.S. Army was more interested in forgetting about it. "The emotions connected with sacrifices made in a lost war ran too deep to permit veterans of that conflict to dwell on their experiences," he wrote in the book's introduction.

When the book was published in 1997, the Army's top brass still blamed its loss on a micromanaging president and a disloyal, left-leaning press that undermined support for the war at home. McMaster instead shifted the blame to some of the Army's most storied generals, whom he faulted for their passivity and willingness to support a policy of gradual escalation that they knew was doomed to failure.

In 2005, McMaster's armored cavalry regiment deployed to Iraq at a moment when U.S. fatalities were climbing and Iraq was slipping into an all-out civil war. In Baghdad, senior commanders were telling their field commanders to consolidate U.S. forces on large secure bases, where they would be less vulnerable to enemy attack, and focus on training beleaguered Iraqi troops to take over the fight.

McMaster, then a colonel, was among a small group of officers who ignored that guidance. He moved his troops off a large, secure air base outside the northern city of Tal Afar and established 29 combat outposts throughout the city. Instead of training Iraqis, his troops focused on stopping the ethnic and sectarian killing in the city.

McMaster's approach caught the attention of Philip Zelikow, a senior aide to then-Secretary of State Condoleezza Rice. Both Zelikow and Rice then fought for it back in Washington. "I talked to other generals who had mixed things to say about H.R. as a commander . . . and personally," Zelikow said. "My view was that this is a guy who is really trying to do something, and he's breaking some [bureaucratic] crockery in the process."

Journalists, academics and officials from Washington think tanks flocked to Tal Afar, often at McMaster's invitation, to study his approach. A 2006 New Yorker article, which received widespread attention in Washington, described McMaster and his men as "rebels against an incoherent strategy."

Despite public praise from President George W. Bush, McMaster was twice passed over for promotion to one-star general upon returning from Iraq. To Zelikow, the Army's failure to elevate one of its smartest officers was a sign of anti-intellectualism in the ranks and "very serious institutional rot."

"Iraq was not the Army's finest hour," he said.

Others in the Army said that the decision reflected McMaster's impatience with underperforming subordinates, his temper and his tendency to clash with superiors. Sometimes, McMaster's passion and intellect worked against him on the battlefield - especially in Afghanistan, where he was chosen in 2010 to lead an anti-corruption task force.

McMaster landed at an inauspicious moment in the counter-corruption effort. Hundreds of millions of U.S. taxpayer dollars were being siphoned from ministries by Afghan officials and flown out of the country to buy beachfront real estate in Dubai.

McMaster's unit was an eclectic mix of soldiers and civilians from various NATO countries and included former fighter pilots, Rhodes scholars, counterintelligence officers, Treasury Department officials and FBI agents.

His brash style alienated many of his American civilian colleagues at the U.S. Embassy and angered his partners in the Afghan government. But even those who hated his management style tended to recognize his brilliance.

"He's not a bull in a china shop," Paul Rexton Kan, a professor who spent a month in Kabul on McMaster's team to help write the anti-corruption strategy, said in an interview for a book on Afghanistan. "He's a bull who picks up the china shop and just smashes it."

With an uncooperative Afghan government, and an Obama administration unwilling to cut off aid money, McMaster's team had little to show for its work after months of effort. His own team called themselves the "Fix the Impossible Task Force" and the "Anti-Gravity Task Force." Several team members described the work environment as "toxic."

In one episode, McMaster demanded that U.S. Justice Department advisers hand over the corruption files kept by the Afghan attorney general and then berated the officials and knocked over a chair when they refused.

That outburst caused a stir back in Washington. People in the meeting were asked to give affidavits about what happened, according to those familiar with the situation. Eric Holder, then the U.S. attorney general, demanded an apology from McMaster.

Trump has demonstrated something of a split-personality when selecting his senior staff and Cabinet. In Mattis, Kelly and McMaster, Trump has chosen brash leaders who speak plainly and frankly. He has also proved quick to fire aides who question his judgment, and he has blackballed senior Republican foreign policy officials who criticized him during his presidential campaign.

In "Dereliction of Duty," McMaster wrote critically of generals who chose not to air their differences with President Lyndon B. Johnson. "Their silence helped to impel the very strategic concept they opposed," McMaster wrote. Soon he will be sitting at the same situation room table deciding what to say.