In meeting after meeting with his national security adviser, H.R. McMaster, this spring and summer, President Trump angrily hammered home two questions:

He wanted to know why the U.S. military wasn’t winning in Afghanistan, and he asked, repeatedly, why, after more than 16 years of war, the United States was still stuck there.

The president’s two questions have defined a contentious debate over whether to send more U.S. troops to Afghanistan to halt two years of Taliban gains. And they have exposed a potentially deep philosophical rift with McMaster, a three-star general.

“H.R. heard the first question and seized on it,” said a senior White House official who is close to McMaster. “But he never heard, or didn’t want to hear, the president’s second question.”

The debate over Afghanistan strategy, which McMaster had ­initially hoped to have resolved by May, continued Thursday when the president and his national security adviser met in the Oval Office. Trump’s reluctance to commit to a new strategy reflects the paucity of good options in Afghanistan and the dim prospects for peace.

[Behind the front lines in the fight to ‘annihilate’ ISIS in Afghanistan]

It also highlights a contradiction at the core of Trump’s foreign policy. On the campaign trail and in conversations with advisers, Trump has said he wants to win and project strength. But he also has called for ending costly commitments in places such as Afghanistan and the Middle East.

The charge for McMaster is to craft a strategy that addresses these contradictory impulses — a desire to simultaneously do more and less in the world — and define the president’s “America first” vision.

McMaster’s challenge is made more difficult by the stylistic differences that separate the two men. McMaster arrived at the White House in February determined to run an apolitical process that would surface the best national security ideas from the vast federal bureaucracy and present options to the president.

But Trump has shown little interest in a methodical and ­consensus-oriented approach. Impatient and determined to shake up U.S. foreign policy, Trump solicits input not only from McMaster but also from friends, family members, Cabinet secretaries and other counselors.

In a disorderly West Wing in which decisions are evaluated not by ideology but by their impact on the Trump brand and their fealty to the president’s campaign-trail promises, McMaster has struggled to become a dominant foreign policy force.

McMaster’s biggest asset is the respect he commands from a Washington foreign policy establishment that has grave doubts about Trump. “Senators and the people the president talks to say, ‘We love H.R.,’ ” said a senior administration official in describing the dynamic between the two men. “The president is very proud of him.”

(Reuters)

But McMaster’s approach has also spawned a fierce rivalry with key players from Trump’s campaign, led by chief strategist Stephen K. Bannon, who views Trump as a revolutionary figure on the world stage.

McMaster’s allies have accused Bannon and his protege Sebastian Gorka, a cable-news mainstay, of waging a concerted campaign to minimize the national security adviser’s influence. Bannon and Gorka have recently become a more regular and outspoken presence at meetings led by McMaster and his team on Afghanistan, the Middle East and the administration’s national security strategy.

McMaster, meanwhile, has in the past two weeks dismissed three National Security Council officials who were viewed as disruptive forces and were seen as close to Bannon.

“Sometimes you have very forceful differences of opinion among the president’s senior advisers,” said Sen. Tom Cotton (R-Ark.), who is close to McMaster and Bannon. “H.R. is indispensable in helping the president hear all those viewpoints and have the information he needs.”

For now, though, those conflicting viewpoints have produced as much chaos as consensus, frustrating the president and fueling speculation about McMaster’s job security. Trump insiders see retired Marine general John F. Kelly, the president’s new chief of staff, as a natural McMaster ally who is seeking to tame the White House’s internecine fights and force the president to stick to a schedule.

Late Friday, Trump issued a statement of support for McMaster amid calls from some conservative activists for his dismissal.

“General McMaster and I are working very well together,” Trump said. “He is a good man and very pro-Israel. I am grateful for the work he continues to do serving our country.”

McMaster’s friends and colleagues are sympathetic to his challenges.

“He had not worked in D.C. before, so this was certainly a new environment for him, but I have always seen him lead,” said Nikki Haley, the U.S. ambassador to the United Nations. “He sets very clear goals. . . . When we’re in those meetings, he’s all about getting options on the table for the president.”

This portrait of the McMaster-Trump relationship is based on interviews with more than 20 senior Trump advisers, NSC officials and friends of both men. Most spoke on the condition of anonymity to offer frank appraisals.

McMaster arrived at the White House after the ouster of his predecessor, Michael Flynn, and with few ties to the president or the Trump administration. Cotton, who recognized Trump’s affinity for generals, brought him to the president’s attention.

“There aren’t that many people who earn decorations for valor who also have best-selling PhD dissertations,” the senator said of McMaster, referring to the general’s book, “Dereliction of Duty: Johnson, McNamara, the Joint Chiefs of Staff, and the Lies That Led to Vietnam.”

Dina Powell, the deputy national security adviser, helped him forge relationships with other Cabinet members and counseled him on how to connect with Trump, according to other administration officials.

McMaster’s first big task, though, was not winning over his boss but earning the trust of his staffers — many of whom were on loan to the NSC from other federal agencies and had been disparaged by some Trump administration officials as “Obama holdovers.”

McMaster tried to ban the term. In his first staff town-hall meeting, he emphasized that as a nonpartisan Army officer he did not vote — a message he delivered repeatedly during his first months. McMaster wanted the NSC’s professional staff to know that he valued its input. He was also sending a message, perhaps unwittingly, to the president, who demands loyalty from his staff and regularly boasts of the size of his electoral-college victory.

McMaster began by compiling a list of 15 strategic problem areas that would guide the council’s work. And he spoke broadly of his concern that U.S. power and influence had been on the decline for much of the past 16 years, said current and former White House officials.

“The president has views that are different than where the establishment has been, and the president appreciates that General McMaster is taking those views and coming back with strategies that give the president options,” said Jared Kushner, the president’s son-in-law and senior adviser.

One of the places McMaster would try to arrest the slide was in Afghanistan, where he had served in 2010 and 2011 and was personally invested. “Fewer and fewer Americans understand what is at stake in the wars in which we are engaged,” he had said in a 2015 speech at Georgetown University. “How many Americans could, for example, name the three main Taliban organizations we are fighting in Afghanistan and Pakistan?”

The American strategy Trump inherited had been defined by the Obama administration’s focus on withdrawing American forces and ending the war.

One key to a better outcome, McMaster argued, was an open-ended commitment that would demonstrate American resolve and compel the Taliban to enter peace talks. McMaster’s version of “America first” in Afghanistan meant negotiating from a position of strength.

Among his biggest challenges was holding the attention of the president. In classified briefings, Trump would frequently flit between subjects. “We moved very quickly from news to intelligence to policy with very little clarity on which lanes we were in,” said a U.S. official who took part in the briefings. “McMaster would act like the tangents didn’t happen and go back to Point 2 on his card.”

Trump had little time for in-depth briefings on Afghanistan’s history, its complicated politics or its seemingly endless civil war. Even a single page of bullet points on the country seemed to tax the president’s attention span on the subject, said senior White House officials.

“I call the president the two-minute man,” said one Trump confidant. “The president has patience for a half-page.”

Another problem was overcoming the president’s skepticism that winning in Afghanistan was even possible.

On Afghanistan, McMaster wanted something that would appeal to the president’s instincts as a promoter, U.S. officials said.

The solution: The general dug up pictures of Kabul’s Massoud Circle from 2005 and 2015 to show how businesses and traffic had returned to the once-desolate area. And he asked one of his Afghanistan experts to find a black-and-white snapshot from 1972 of Afghan women in miniskirts walking through Kabul.

“The goal was to give the president the idea that Afghanistan was not this hopeless place,” said one U.S. official familiar with the briefing, which included several pictures of the country.

The briefing did not change Trump’s position, which had been shaped by his two years on the campaign trail and his sense that the American people had lost sight of the war’s purpose. The strategy review that McMaster had hoped to complete by early May — ahead of a NATO conference where he hoped to secure pledges for more European troops — remains stalled.

At McMaster’s urging, Trump earlier this summer signed an order giving the Pentagon the authority to send as many as 3,900 more troops requested by commanders to Afghanistan. But Defense Secretary Jim Mattis, concerned about the absence of an approved strategy and chastened by Trump’s doubts about the war, has not authorized the forces to go.

At a meeting last month, the president angrily complained that the United States was not winning in Afghanistan, suggested firing the current commander and questioned whether sending more troops to the country would be folly, said U.S. officials familiar with the meeting. The first detailed accounts of the meeting were reported by NBC News.

The fight over the Afghanistan strategy points to a larger problem with the relationship between McMaster’s NSC and the West Wing. During his six months on the job, McMaster has raised morale among the career staffers, who describe him as open and accessible.

He has put in place a rigorous and structured process that integrates the views of agencies across the government.

Less clear is whether any of that work is resulting in new policies. A Pentagon strategy aimed at defeating the Islamic State was completed in early March but still has not been approved by the president, officials said.

The administration instead has worked piecemeal to give U.S. commanders in Iraq and Syria more latitude to increase the pace of military operations. Potentially divisive questions about the United States’ long-term goals and military presence in the region — the same issues being debated in the Afghanistan review — remain unresolved.

Julie Tate contributed to this report.