WASHINGTON — President Barack Obama is expected to announce a plan Thursday to keep 5,500 U.S. troops in Afghanistan into 2017, ending his ambitions to bring home most American forces from that war-torn country before he leaves office.

The president’s decision came after an “extensive months-long review” that included regular discussions with Afghanistan’s leaders, his national security team and U.S. commanders in the field, a senior administration official said.

Obama will also slow the pace of the reduction of American forces and plans to maintain the current U.S. force of 9,800 through “most of 2016,” said the official, who spoke anonymously to preview the president’s announcement.

The post-2016 force would still be focused on training and advising the Afghan army, with a special emphasis on its elite counterterror forces. The United States would also maintain a significant counterterrorism capability of drones and Special Operations forces to strike al-Qaeda and other militants who may be plotting attacks against the United States.

The revised troop plans came just weeks after the Afghan forces were driven from Kunduz, the first major city to fall to the Taliban since the war began in 2001. The Afghans, with some support from U.S. planes and Special Operations advisers, have in recent days been able to take the city back from the Taliban.

Obama’s decision also follows the collapse of the U.S.-trained Iraqi army in northern and western Iraq under pressure from Islamic State militants.

The decision is a significant departure from the exit plan that Obama announced in a White House Rose Garden speech in May 2014. In keeping with his promise to “turn the page” on the costly wars launched by his predecessor, Obama said then that he would reduce the U.S. military footprint to around 1,000 troops, all based in Kabul, by the end of 2016.

That minimal force would have prevented the U.S. military from advising Afghan forces in combat or conducting counterterrorism operations against al-Qaeda or threats to the homeland.

The larger force of 5,500 troops is projected to cost about $15 billion a year, or about $5 billion more than the smaller, 1,000-person Kabul-based force would have cost.

The change in course acknowledges the struggles of the Afghan forces, which are suffering casualties at an “unsustainable” rate, senior military officials said, and have been losing some ground to the Taliban. The president’s decision is not directly related to the fall of Kunduz, administration officials said.

“This specific posture has been under consideration for months,” the administration official said. “Obviously we were mindful of the dynamic security situation.”

Obama discussed the decision in a call Wednesday with Afghan President Ashraf Ghani, who has pressed American officials to commit to staying longer in his country, officials said, speaking on condition of anonymity to discuss internal deliberations.

Under the proposal approved by Obama this week, the U.S. military would retain bases in Kabul, as planned, but also have forces at Bagram Air Base and at bases outside Kandahar and Jalalabad, the largest cities in Afghanistan’s southern and eastern regions.

The decision is a stark illustration of how persistent militant threats have stood in the way of Obama’s promises to end the ground wars that have dominated U.S. foreign policy since the Sept. 11, 2001, attacks. Last week, U.S. troops launched a major operation against al-Qaeda in Kandahar, the Taliban’s historic heartland. U.S. aircraft conducted 63 strikes in support of Afghan forces who staged an assault against two militant bases, one of which covered an area of nearly 30 square miles, according to Brig. Gen. Wilson Shoffner, a spokesman for U.S. forces. Those strikes targeted forces aligned with al-Qaeda, the military said.

The extended Afghanistan presence could be part of a global network of counterterrorism facilities that, according to a plan championed by Gen. Martin E. Dempsey, former chairman of the Joint Chiefs of Staff, would allow the United States to better manage acute threats without requiring large conventional forces on the ground.

Despite 14 years of military operations by the United States and other NATO nations, Afghanistan remains a dangerous place. This week, even as the Taliban withdrew from Kunduz, the northern city they seized late last month, the militants were advancing on other urban areas.

Al-Qaeda appears to have staked out new ground outside the remote mountain areas along the Afghanistan-Pakistan border, where its fighters have been relegated in recent years.

“That’s what this debate is about: how much we are willing to invest in preventing Afghanistan’s return as a serious threat to the region,” said James Cunningham, the U.S. ambassador in Kabul until 2014. “I’m convinced that’s what’s going to happen if we withdraw too rapidly.”

Obama reviewed several proposals for a post-2016 force over the spring and summer before finally settling on the current plan, which was based on a plan brought forward in August by Dempsey, officials said.

Only subscribers are eligible to post comments. Please subscribe or to participate in the conversation. Here’s why.

Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.