The U.S. was supposed to leave Afghanistan by 2017. Now it might take decades.

Afghan security personnel inspect the area near a damaged vehicle in Kabul. (SHAH MARAISHAH MARAI/AFP/Getty Images)

Top U.S. military commanders, who only a few months ago were planning to pull the last American troops out of Afghanistan by year’s end, are now quietly talking about an American commitment that could keep thousands of troops in the country for decades.

The shift in mind-set, made possible by President Obama’s decision last fall to cancel withdrawal plans, reflects the Afghan government’s vulnerability to continued militant assault and concern that terrorist groups such as al-Qaeda continue to build training camps whose effect could be felt far beyond the region, said senior military officials.

At a news conference Thursday, Oct. 15, President Obama says the U.S. will maintain 9,800 troops in Afghanistan through most of 2016 and will not go down to a normal embassy presence by the end of 2016, but instead will keep 5,500 troops at a small number of bases. (AP)

The new American outlook marks a striking change for Obama, who campaigned on a promise to bring American troops home and has said repeatedly that he does not support the “idea of endless war.” And it highlights a major shift for the American military, which has spent much of the past decade racing to hit milestones as part of its broader “exit strategy” from Afghanistan and Iraq. These days, that phrase has largely disappeared from the military’s lexicon.

In its place, there is a broad recognition in the Pentagon that building an effective Afghan army and police force will take a generation’s commitment, including billions of dollars a year in outside funding and constant support from thousands of foreign advisers on the ground.

“What we’ve learned is that you can’t really leave,” said a senior Pentagon official with extensive experience in Afghanistan and Iraq who like others spoke on the condition of anonymity to describe internal discussions. “The local forces need air support, intelligence and help with logistics. They are not going to be ready in three years or five years. You have to be there for a very long time.”

Senior U.S. commanders have also been surprised by al-Qaeda’s resilience and ability to find a haven in the Afghan countryside, as well as the Taliban’s repeated seizure of large tracts of contested territory.

In November, the U.S. military sent a company of elite U.S. Rangers to southeastern Afghanistan to help Afghan counterterrorism forces destroy an al-Qaeda training camp in a “fierce fight” that lasted for several days.

The training camp was “absolutely massive,” said Brig. Gen. Wilson Shoffner, a military spokesman in Afghanistan.

“No matter what happens in the next couple of years Afghanistan is going to have wide ungoverned spaces that violent extremist organizations can take advantage of,” Shoffner said. “The camp that developed in southeastern Kandahar is an example of what can happen.”

There are now 9,800 U.S. troops in Afghanistan, some of them advising local forces and some focused on hunting down al-Qaeda and other hard-line militants. Plans call for Obama to halve that force by the time he leaves office, but he could defer the decision to the next president.

The U.S. military’s current thinking reflects its painful experience in Iraq, where Iraqi army forces collapsed less than three years after American forces left in 2011.

And it’s echoed in the arguments made by many Republican and Democratic foreign policy advisers, looking beyond the Obama presidency, for a significant long-term American presence. “This is not a region you want to abandon,” said Michèle Flournoy, a former Pentagon official who would probably be considered a top candidate for defense secretary in a Hillary Clinton administration. “So the question is what do we need going forward given our interests?”

In Helmand province, where American troops suffered the heaviest losses of the war, Afghan units have struggled to hold on to territory taken by American forces from the Taliban in 2011 and 2012. “There’s a real will-to-fight issue there,” said a senior military official in Kabul.

Senior American commanders said that the Afghan troops in the province have lacked effective leaders as well as the necessary weapons and ammunition to hold off persistent Taliban attacks. Some Afghan soldiers in Helmand have been fighting in tough conditions for years without a break to see family, leading to poor morale and high desertion rates.

Gen. John F. Campbell, the top American commander, has sent Special Operations forces to the province to help direct American airstrikes and provide help with planning. An American soldier was killed and two others were wounded this month fighting alongside the Afghans.

In addition, about 300 U.S. troops in Helmand are advising Afghan commanders at the corps level, well removed from the front lines.

The American support is designed to arrest the immediate losses, but building an effective and sustainable fighting force that can manage contested areas such as Helmand province, will take many years, U.S. military officials said.

Foreign officials say the Afghan units lack effective mid-level officers and sergeants who can lead troops in combat and are not captive to patronage networks that dominate the country and sap soldier morale. Seeding the force with mid-level officers often requires bringing in young leaders from outside the current system and training them from scratch.

“I think a generational approach has value,” Shoffner said.

Senior U.S. officials point to improvements in areas such as evacuating wounded troops from the battlefield. As recently as 2013, it took the Afghan army 24 hours on average to get medical assistance to wounded troops. Now help usually arrives in four hours, still longer than desired. But other critical goals, such as building an effective resupply system for the country or a capable air force, cannot be accomplished in a few years. Many of the American pilots flying in Afghanistan have 10 to 15 years of experience.

“How long does it take to grow a 15-year pilot? It takes about 15 years,” Shoffner said. “We’re starting a little late with the air force.”

Senior U.S. military officials and some former Obama administration officials increasingly compare the U.S. government’s plans for Afghanistan to its approach to South Korea, where it has maintained tens of thousands of troops for decades. Other top officials cite the example of Colombia, where the United States has long provided training, money and contractors.

“Our presence right now helps serve as a significant bulwark against instability and at a cost that I think is reasonable to bear,” said Daniel Feldman, who until recently served as the Obama administration’s special representative for Afghanistan and Pakistan. “Particularly if we’re not proposing a significant combat role, I think the American people would be open to the argument of sticking with Afghanistan.”​

U.S. officials said that in Afghan President Ashraf Ghani they have a willing and reliable partner who can provide bases to attack terrorist groups, not just in Afghanistan but also throughout South Asia, for as long as the threat in the chronically unstable region persists.

The difference between Afghanistan and other long-term American commitments in South Korea and Colombia is that Afghanistan remains a far more dangerous and unstable place for American personnel. Even though Afghan troops have assumed the lead combat role throughout the country, with U.S. troops in an advisory role, Americans still face real dangers and have taken recent casualties there.

In some cases, senior U.S. officials have been surprised by the Taliban comeback in the past year. Emboldened by the departure of most foreign forces, Taliban fighters have seized district centers, inflicted heavy losses on government forces and temporarily overrun a provincial capital. Now, Afghan forces must also grapple with an aggressive local branch of the Islamic State.

Some officials hold out hope that a long-term military presence might be unnecessary, if hoped-for peace talks with the Taliban make progress. The Afghan government has asked Pakistan, home to many Taliban leaders, to push the militants into talks.

A generational U.S. footprint “doesn’t need to be the case,” said Jeff Eggers, a former senior White House official with long experience working on Afghanistan and Pakistan. “The Korea model is not necessary if the peace process moves forward — that’s the preferred path for all parties.”

The obstacles to peace talks, though, are huge. Senior officials in Kabul and Islamabad, Pakistan, are riven by suspicion, and the Taliban remains deeply fractured following the revelation that its longtime leader, Mohammad Omar, has been dead for more than two years.