In May 2014, President Obama arrived at the U.S. Military Academy, where he laid out his philosophy for how and when to use American military power. (Jim Watson/AFP/Getty Images)

In meeting after meeting this spring and summer, President Obama insisted that the last American troops in Afghanistan would return home by the end of his presidency, definitively ending the longest war in American history.

Obama and his closest foreign policy advisers laid out the reasons for his military commanders. Keeping as many as 10,000 troops in Afghanistan indefinitely at a cost of as much as $10 billion to $15 billion a year wasn’t politically feasible or financially responsible. There were more pressing domestic priorities that needed money. The country faced bigger threats.

Then, in August, Gen. Martin E. Dempsey, the outgoing chairman of the Joint Chiefs of Staff, came in with one more plan to maintain a counterterrorism force of as many as 5,000 troops in Afghanistan to prevent a reemergence of al-Qaeda and to battle Islamic State fighters seeking a foothold in the country. Dempsey’s plan was a quick, ­back-of-the-envelope exercise, according to senior administration officials.

This time, though, Obama didn’t dismiss it. “I think that’s an argument that can be made to the American people,” Obama said, according to a senior administration official who took part in the meeting and who, like others interviewed for this article, spoke on the condition of anonymity to discuss internal deliberations.

Obama had come to office with a deep skepticism of the U.S. military’s ability to bring order to broken and chaotic societies. His experiences over the course of his two terms in office had reinforced his instincts to the point that the phrase “no military solution” had become a mantra that he deployed to describe not just Afghanistan but also half a dozen other conflicts in places including Libya, Syria and Ukraine.

In this 2014 statement made from the White House, President Obama announces plans to leave only 9,800 troops in Afghanistan after 2014 and to withdrawal all combat troops by the end of 2016. (WhiteHouse.gov)

This is Obama’s mind-set as he weighs a decision on whether to leave troops in Afghanistan past his presidency. It is a choice that would contravene a long-held personal desire and central tenet of his election campaigns — a definitive end to the wars he had inherited. His struggle shows how a president who once described war as an “expression of human folly” has come to wield force on battlefields where America’s interests often seem peripheral to him and where its enemies are brutal and determined.

Similar dilemmas had consumed his predecessors. Bill Clinton, after an agonizing debate, didn’t deploy troops to stop genocide in Rwanda, but he dispatched U.S. forces to halt ethnic cleansing in Bosnia and Kosovo. In the wake of 9/11, George W. Bush sought to stamp out the terror threat by toppling governments and trying to build democracy in Iraq and Afghanistan.

Obama has defined American interests more narrowly than Bush or Clinton, convinced that the country’s biggest and costliest mistakes over the past 50 years have been the product of American military overreach.

His hesitancy to commit U.S. forces is especially evident in the way he talks about America’s military might. “His rhetoric is not in the traditional American vein,” said Andrew Bacevich, a retired Army colonel and history professor at Boston University. “It comes from a different place — one of ambivalence, complexity and a reluctance to sound crusading notes.”

Obama has launched military strikes in seven countries. He ended a war in Iraq only to recommit thousands of American troops there when Islamic State insurgents routed the U.S.-trained Iraqi army in Mosul. A few weeks later, he ordered the U.S. military to start bombing Islamic State strongholds in Syria.

Afghanistan has been the one constant that spans his two terms in office. As an inexperienced president, Obama decided to send more than 50,000 American troops into Afghanistan in an attempt to blunt the Taliban’s momentum, bolster the Afghan army and improve the prospects for reconciliation in a country that had experienced three decades of civil war.

Nearly seven years later, the leaders of Afghanistan’s new unity government were still feuding, Afghan security forces were losing ground to insurgents, and the prospects for reconciliation with the Taliban seemed bleak.

In early October, Obama summed up one of the biggest lessons he’s taken from America’s interventions in these fractured societies. “What we’ve learned over the last 10, 12, 13 years is that unless we can get the parties on the ground to agree to live together in some fashion, then no amount of U.S. military engagement will solve the problem,” he said at a news conference.

What kind of difference could U.S. troops make in such deeply divided and chaotic countries? What were the risks of leaving? These were the questions that Obama would have to answer in Afghanistan. They were the sorts of questions that had come to define his presidency.

Military strategy hits a snag

One year ago, Obama laid out his philosophy for how and when to use American military power in a carefully constructed speech at the U.S. Military Academy.

He had touched on the subject in previous addresses: before sending troops to Afghanistan, launching airstrikes in Syria, plunging the U.S. military back into Iraq. The subject had been the focus of his 2009 Nobel Peace Prize address and a major speech on drone warfare.

The speech at West Point was supposed to be the definitive word.

The United States would continue to use force unilaterally “when our core interests demand it — when our people are threatened, when our livelihoods are at stake, when the security of our allies is in danger,” Obama said. This was the rationale driving his drone campaign and Special Operations raids.

These sorts of operations were low-cost but limited in what they could achieve. Often they provoked fury and resentment overseas.

To bring order to places such as Afghanistan, Yemen, Libya and Iraq, the United States needed to train allies on the ground, Obama said. The centerpiece of the president’s strategy to address this larger problem was a $5 billion Counterterrorism Partnerships Fund that would help the nation recruit, train and equip local forces.

Today, the strategy that Obama outlined at West Point is in tatters. Congress gave Obama only $1.3 billion of the $5 billion he requested in 2015 to train local partners. Senior congressional staffers complained that the White House and Pentagon could never explain how and where they planned to spend all that money.

Even when there was money to build local forces, America’s allies, many of whom were beholden to corrupt or sectarian governments, frequently lacked the will to fight. Three weeks after Obama’s West Point speech, lightly armed Islamic State rebels seized Mosul, crushing Iraqi army units that had been the recipients of years of training and billions in aid and equipment. Then U.S.-backed forces in Yemen fell apart when that country dissolved into civil war. In Syria, the $500 million U.S. training and equipment program has produced only four trained fighters.

“Is it possible to build an indigenous force that will actually take control of its own destiny?” Dempsey, who spent two years overseeing the training of the Iraqi army, asked in a recent interview with Joint Forces Quarterly. “I don’t know.”

The failure to find capable local partners or build effective indigenous forces was driving the president to rely more heavily on fighter jets and drones. Even as drone strikes diminished in Pakistan, where al-Qaeda had been badly damaged, they were ramping up in Syria and Iraq.

These long-distance sniper shots were hardly satisfying to the White House or the military, which saw its mission as fighting and winning the nation’s wars. But neither the president nor his commanders saw better options.

“Everywhere I’ve gone for the past year — shoot, the past decade — I hear the mantra that we can’t kill our way to victory. I never disagree,” said a senior U.S. military commander involved in counterterrorism operations. “However, with no clear strategy, there’s lots of killing to be done to keep the wolves at bay and buy space and time. My only satisfaction is that we aren’t wasting precious American lives while we figure things out.”

Debate within White House

Here’s what Obama and his war cabinet were trying to figure out earlier this year in Afghanistan: If they kept withdrawing forces under the president’s current plan, would Afghan troops crumble and would the government fall apart?

Chastened by the collapse of Iraqi forces a few months earlier and the Afghan army’s battlefield struggles, U.S. military commanders were asking Obama to freeze troop levels at 9,800 this year, a departure from the president’s plan to shrink to about 5,000.

Afghanistan’s new president, Ashraf Ghani, was eager to maintain a large American presence as well.

The request from Ghani and the military provoked an emotional debate inside the White House. The United States had been working with the Afghan army and police forces for more than a decade, said James R. Clapper Jr., Obama’s director of national intelligence. Just about every plan to cut troop levels was met with a request from the military to slow the withdrawal. The extra troops and time never seemed to be enough.

“What’s the definition of insanity?” Clapper asked during one White House meeting, according to several administration officials. “It’s doing something over and over and expecting different results.”

Susan E. Rice, Obama’s national security adviser, took a similar position. The Afghan troops’ struggles had been foreseeable when the president and his team agreed to the drawdown plan.

“We all had hands on that decision,” she said, according to the administration officials. “What’s changed?”

The final word fell to Obama, who told the Pentagon that he was willing to freeze troop levels at 9,800 for the remainder of 2015, but that he was still determined to bring home the vast majority of U.S. troops before he left office.

Vice President Biden summed up the logic driving Obama’s split-the-difference decision for Ghani when the Afghan leader visited the White House in March. Afghanistan was important, Bi­den said, according to a senior administration official who was present at the meeting. But the White House faced more pressing threats elsewhere. “The wolf at the door is not Afghanistan,” Biden told Ghani.

Obama’s withdrawal plan for Afghanistan has provoked nearly universal alarm among those in the Washington foreign policy establishment who follow the country closely.

“I don’t know why he sticks to it so relentlessly,” said Bruce Riedel, a former CIA official who helped lead Obama’s initial 2009 review of Afghanistan and Pakistan policy.

“When things have collapsed, completely collapsed, in Afghanistan, it has been when the international community abandons them or they have no outside international support,” said Michele Flournoy, who was among Obama’s top choices to be defense secretary last year before Ashton B. Carter was nominated.

“We are an impatient people — that’s what built the nation,” said Ryan Crocker, who was ambassador to Iraq and Afghanistan under Obama. “But impatience doesn’t work in places like Afghanistan.”

These days, Crocker says, keeping a force of 10,000 to 15,000 U.S. troops in the country indefinitely would be enough to allow the Afghan government to muddle through without feeling completely abandoned by the West. “The stakes are pretty high, and the costs are quite manageable,” he said.

‘Don’t want to screw this up’

Crocker met Obama for the first time in 2009. It was 3 a.m. in Baghdad, and Crocker was about to brief him on the political situation in Iraq.

He didn’t know quite what to expect from the president, who as a state senator had warned that a U.S. invasion of Iraq would lead to a protracted and bloody occupation. Six years later, as a presidential candidate, Obama had run on a promise to pull all U.S. combat brigades from Iraq in the first 16 months of his presidency.

Now he was the commander in chief staring up at the videoconference images of Crocker and Gen. Ray Odierno, two men who between them had spent more than eight years in Iraq. It was Obama’s first full day in office, Crocker recalled.

Crocker had just started his briefing when Obama held up his hand to stop him. The confidence and cool that were so evident on the campaign trail seemed to have vanished.

“There’s just one thing,” Crocker recalled the new president saying. “I just don’t want to screw this up.”

That president was above all a pragmatist, the kind of leader who wanted to “figure out what it takes to get it right and do it,” Crocker said. “The interesting question becomes: If his instincts seemed to be pretty sound and farsighted, what happened then?”

Obama offered up one answer to that question in a meeting with foreign policy columnists at the White House earlier this year. “In terms of decisions I make, I do think that I have a better sense of how military action can result in unintended consequences,” he said. “There’s always going to be complications.”

His time as commander in chief also had made him far more dismissive of a Washington foreign policy establishment that frequently disparages him as too cautious or hesitant to dispatch American firepower.

“Mumbo jumbo” was the phrase he used in a recent news conference to describe his critics’ calls for the United States to impose a no-fly zone in Syria to stop that country’s president from dropping barrel bombs on his own people.

A few weeks earlier, he had complained to a group of Iraq and Afghanistan veterans who were visiting the White House that if he listened to his critics in Congress “who holler all the time, we’d be in like seven wars right now. I’m not exaggerating. I can count them.”

The ‘no kidding’ price tag

His harshest critique came this summer in a speech defending the Iran nuclear deal. To prepare for it, Ben Rhodes, the president’s longtime speechwriter, reread Obama’s 2002 speech decrying the coming war in Iraq.

In it, Obama had lambasted Paul D. Wolfowitz, one of the war’s architects, as an “armchair, weekend warrior” and branded President George W. Bush’s longtime adviser Karl Rove a “political hack.” The coming Iraq war, Obama said, was an effort by the Bush administration to “shove their ideological agendas down our throats.”

The president wanted that same sense of moral certainty to infuse his 2015 Iran speech. This time, Obama described a mind-set in Washington that too often put military action ahead of diplomacy, and he decried previous leaders who “did not level with the American people about the costs of war.”

These were the same people who were fighting the Iran deal, Obama said, “the same people who seem to have no compunction with being repeatedly wrong.”

Obama wanted the speech to make people uncomfortable. “The fact that it was controversial was the point,” Rhodes said. “People don’t like being called out.”

How did the certain logic of the Iran deal apply to places such as Iraq, Syria and Afghanistan where Obama saw more complexity than clear answers — where Obama was trying to end a messy war, rather than prevent one?

The day before Obama delivered the Iran speech, Dempsey briefed the president on his hastily assembled plan to keep as many as 5,000 troops in Afghanistan beyond 2016 and the end of Obama’s presidency.

Obama asked his general to come back to him with more details about the “no kidding” cost of keeping the American force in the country over the long term. He had learned that the Pentagon’s estimates often didn’t include paying thousands of civilian contractors.

The president wanted a clearer sense of the troops’ mission, which he worried would inevitably expand without tight controls, and he asked Dempsey and the CIA for a better sense of the threat.

These were the sorts of questions that Obama hadn’t known to ask in the earliest days of his presidency when he invited Riedel, the former CIA analyst who had been leading his initial 2009 review of Afghanistan and Pakistan policy, to join him on Air Force One for a flight to California.

The two had spent nearly four hours on the plane discussing the need to bolster the struggling Afghan army and press Pakistan to end its support for the Taliban insurgency. Just before the plane landed, Obama had shared a final thought.

“I just don’t want to leave this kind of mess for my successor,” he said.

That Obama had surged more than 50,000 U.S. troops into Afghanistan. This Obama was different — older, more skeptical and more certain of the need to end America’s wars. And yet, he told Dempsey to come back in a few weeks with a more detailed proposal.

The president who had vowed to get out of Afghanistan would now take seriously a plan for staying there.