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".
More about: