President Barack Obama has confirmed plans to extend the US military presence in Afghanistan beyond 2016, in a shift in policy.
Speaking at the White House, he said the US would keep 5,500 troops in the country when he leaves office in 2017.
Originally all but a small embassy-based force were due to leave by the end of next year.
But the US military says more troops will be needed to help Afghan forces counter a growing Taliban threat.
There are currently 9,800 US troops stationed in Afghanistan.
The US forces will be stationed in four locations - Kabul, Bagram, Jalalabad and Kandahar.
'The right thing'
Announcing the plan on Thursday, President Obama said the troop extension could "make a real difference" for Afghanistan and Afghan security forces, which he acknowledged were "not as strong" as they needed to be.
He said the ending of Nato combat operations in December last year had come at a price, with many Afghan troops and civilians killed since the Taliban stepped up its insurgency.
"It's the right thing to do," the president said about the policy change. "As commander in chief I will not allow Afghanistan to be used as safe haven for terrorists to attack our nation again."
For the Taliban, he continued, it should be clear that the only way to achieve a full pullout of US troops is through a lasting settlement with the Afghan government.
He described the mission in Afghanistan as "vital to US national security interests".
Analysis: Jonathan Marcus, BBC defence and diplomatic correspondent
The slowing of the withdrawal of US troops from Afghanistan means that President Obama will not be able to bring home all US forces before his presidency ends.
A US review of its troop presence there has been under way for some months and is not directly linked to the Taliban's recent success in briefly seizing the town of Kunduz.
But that episode illustrated the continuing need for the US training and mentoring of Afghan forces.
With al-Qaeda again operating in Afghanistan and the so-called Islamic State gaining a foothold, Washington is also eager to retain a small number of bases from which it can mount counter-terrorist operations.
Whatever the hopes of a full US withdrawal, it now looks as though Washington is set to have a continuing military commitment to Afghanistan, where US air power in particular plays an essential role.
President Obama had previously planned to reduce the number of troops left in Afghanistan to about 1,000 by the time he left office in January 2017.
An earlier statement from the US National Security Council said the change in policy was the "result of an extensive, months-long review", and after Mr Obama had consulted "with his full national security team and our Afghan partners".
"This announcement in no way changes the fact that our combat mission in Afghanistan has ended, and we will continue to undertake only two narrow missions: counterterrorism and training, advising, and assisting our Afghan partners," the statement went on.
Afghan President Ashraf Ghani is expected to welcome the move, as he had been pushing for a slower withdrawal of US troops to allow Afghan forces to be better trained and equipped.
The top US military commander in Afghanistan, Gen John Campbell, expressed concern last week over the "tenuous security situation" and said an enhanced military presence would be necessary if the Taliban were to be repelled.
He was speaking days after the Taliban briefly seized the northern city of Kunduz - their most spectacular military gain since being ousted from power in 2001.
Read more on Afghanistan:
After the Taliban's surprise attack on Kunduz, Afghan government forces managed to retake control of key areas of the city with the aid of Nato special forces and US air strikes.
But the city's brief capture was seen as a setback for the Afghan authorities under pressure to show they can keep the country secure without the backing of international forces.
The south-eastern city of Ghazni has also seen fierce clashes between Taliban insurgents and US-trained Afghan troops in recent days.
Militant violence has increased across Afghanistan since Nato ended its combat mission there in December 2014, leaving a residual force - mainly US troops - used for training and counter-terrorism operations.
The shift in policy comes at the same time as three separate investigations - by the US, Nato and Afghan authorities - into a US air attack on an MSF-run hospital in Kunduz that killed 22 people.
The US said the bombing was a mistake, and President Obama later apologised.