President Obama's long dream of concluding the war in Afghanistan before he departs the White House officially ended Thursday with the announcement that the U.S. will leave up to 5,500 troops there into 2017.

The announcement came after months of bad news from Afghanistan: The Taliban has scored a series of battlefield victories, the Afghan army's casualties are soaring and there are mounting worries that the Islamic State is gaining a foothold in rural areas.

"Afghan forces are still not as strong as they need to be," Obama said in a White House news briefing Thursday morning.

"While America's combat mission in Afghanistan may be over, our commitment to Afghanistan and its people endures. As commander in chief, I will not allow Afghanistan to be used as [a] safe haven for terrorists to attack our nation again," Obama said.

His new plan will extend today's force level of about 9,800 troops in Afghanistan through most of next year, with a new goal to bring that number down to about 5,500 by 2017.

The previous plan that Obama announced in 2014 aimed to cut the force down to about 5,000 next year and leave only about 1,000 troops to protect the U.S. Embassy in Kabul by January 2017.

As a result of the new plan, several thousand troops, mostly soldiers and airmen, will receive six-month and nine-month deployment orders next year to support the extended force presence.

In addition to a small force in Kabul, the U.S. military likely will extend its presence elsewhere, including Bagram Airfield, Jalalabad in the east and Kandahar in the south, Obama said.

"The mission will not change; our troops will focus on training Afghans and counterterrorism operations. But these bases will give us the presence and the reach our forces require to achieve their mission," he said.

Obama said several new factors have put Afghanistan at risk since he outlined his original drawdown plan in 2014.

"Pressure from Pakistan has resulted in more al-Qaida (fighters) coming into Afghanistan, and we have seen the emergence of an [Islamic State] presence," he said. "The bottom line is, in key areas of the country, the security situation is still very fragile. And in some places there is risk of deterioration."

Obama characterized the drawdown change as a "modest and meaningful extension" and repeatedly noted that the troop levels now planned are far below the peak of about 100,000 that were deployed to Afghanistan in 2010.

Obama spoke directly to troops during the announcement: "To our men and women in uniform, I know this means that some of you will rotate back into Afghanistan. Afghanistan remains a dangerous place. ... I do not send you into harm's way lightly. It's the most solemn decision that I make.

"But as your commander in chief, I believe this mission is vital to our national security interests in preventing terrorist attacks against our citizens and our nation," Obama said.

Afghan security forces have struggled to contain the Taliban insurgency since the U.S. ended its "combat mission" in December 2014 and declared an official end to Operation Enduring Freedom.

The Taliban recently seized the northern city of Kunduz, its biggest battlefield victory since 2001. Afghan troops have launched a successful counteroffensive but fighting reportedly continues.

Recent United Nations data suggest the Taliban's operations and influence now reach further than at any point since 2001.

Casualties among Afghan security troops have spiked this year as the fledgling force struggles without as much air and medevac support from the U.S.

The Islamic State group's stronghold remains in Iraq and Syria. But U.S. military officials in Afghanistan say militants are "operationally emergent" in Afghanistan and are starting to rival the Taliban for control and influence across the country.

At least one U.S. airstrike targeted a regional Islamic State leader in July in Nangahar province, according to Afghan intelligence officials.

A year and a half ago, Obama vowed to bring the entire military mission in Afghanistan to a close. "It's time to turn the page on more than a decade in which so much of our foreign policy was focused on the wars in Afghanistan and Iraq," he said in May 2014.

But those plans have been withering for more than a year, in part because the Islamic State group's big victories in Iraq last summer raised new concerns in Washington about the underlying strategy of ending direct military support missions and leaving host-nation security forces to do the job.

Instead of fulfilling a top campaign promise to bring nearly all U.S. troops home from Afghanistan by the end of his second term, Obama likely will hand off to the next president responsibility for a conflict that will be entering its 16th year.

Sen. John McCain, R-Ariz., said Obama's extended commitment to Afghanistan is not enough.

"I am concerned that the number of troops will not be sufficient to perform the critical tasks being set for them: counterterrorism and continuing to train and advise our Afghan partners," McCain said in a statement Thursday. "The bottom line is that 5,500 troops will only be adequate to conduct either the counterterrorism or the train-and-advise mission, but not both.

"It would have been far better to halt all further troop withdrawals and allow President Obama's successor to determine what is warranted based on conditions on the ground."