Updated on October 15 at 2:06 p.m. ET

President Obama announced Thursday that U.S. troops will remain in Afghanistan past 2016.

The president said the U.S. will maintain 9,800 troops in the country through most of next year. They will focus on training Afghan security forces and counterinsurgency efforts. After that period, 5,500 troops will remain in a small number of bases, including Bagram, Kandahar, and Jalalabad, he said.

The “cessation of our combat role has not changed,” Obama said, adding: “This is consistent with the overall vision that we’ve had.”

But the move, on which we reported Wednesday, is a reversal of the president’s previous position that all U.S. troops withdraw from the country by the end of next year, but it comes as the Taliban continues to grow in strength, al-Qaeda remains in pockets, and the Islamic State gains ground in Afghanistan.

Obama said that while Afghan security forces continued to “step up, … they are still not as strong as they need to be.” He noted that the Taliban had made gains, particularly in rural Afghanistan. He said the situation in Afghanistan remained “still very fragile, and in some places there’s the risk of deterioration.”

The Obama administration had previously planned to reduced the number of troops in Afghanistan by about half, and then keep about 1,000 troops at the U.S. Embassy in Kabul.

“I expect that we’ll continue to evaluate going forward, as will the next president,” Obama said on Thursday’s decision.

At the Pentagon, Defense Secretary Ash Carter added that the decision on troop levels was made because “America’s national security remains very much at stake.” He said the U.S. was “not going to give up the gains we fought so hard to achieve.”

At the White House briefing, spokesman Josh Earnest was asked when the U.S. would reduce the number of troops to embassy-only levels. His reply: “I think the question you're asking is ultimately one that will answered by the next commander in chief.”

As we reported Wednesday:

The apparent White House rethink has been prompted by a confluence of factors: The Taliban’s capture of Kunduz late last month, the group’s biggest prize since it was removed from power by the U.S.-led invasion in 2001; the fact the militants are more spread out across Afghanistan than at any point since 2001; the continued presence of al-Qaeda in Afghanistan’s mountains; and inroads being made by the Islamic State, a group whose tactics and brutality the world is becoming increasingly familiar with in Iraq, Syria, and elsewhere.

Even before the recent gains made by the insurgents, the Obama administration had been under pressure from the military, some members of Congress, and the Afghan president to rethink the original plans for a troop drawdown.

“Obviously, we’re mindful of the dynamic security situation, and we’re watching and seeing how the Afghan security forces engaged quite tenaciously in the fighting for Kunduz,” the New York Times quoted a senior administration official as saying. “But this posture and this number has all been under discussion for months.”

But continued involvement in Afghanistan comes at a cost: Despite being in the country for 14 years, and training Afghan troops—an effort that has cost $65 billion—Afghanistan remains restive. The inability of Afghan security forces to hold onto Kunduz in the face of a long-planned Taliban onslaught, and their retaking of the city only with U.S. help are only likely to raise more questions about what the U.S. hopes to achieve past 2016.