Barack Obama noted the terrible toll the Afghan war exacted when he led tributes on Memorial Day
The US will keep 9,800 troops in Afghanistan after concluding its combat mission at the end of this year, President Barack Obama has said.
Under the plan he announced at the White House, the US will then gradually withdraw troops until only a small residual force remains after 2016.
The remaining troops would guard the US embassy, train Afghan forces and support counter-terrorism operations.
But the plan depends on the Afghans signing a joint security agreement.
While current Afghan President Hamid Karzai has refused to sign such an agreement, the Obama administration appears to be confident either of the two candidates seeking to replace him would do so.
"This year, we will bring America's longest war to its responsible end," Obama said.
Obama described the timing for the withdrawal:
Beginning of 2015: 9,800 troops spread out across Afghanistan
End of 2015: About half that number, concentrated in Kabul and at nearby Bagram Air Base
End of 2016: Fewer than 1,000 troops remain to guard the US embassy, train Afghan troops, and a "security assistance component"
"We will no longer patrol Afghan cities and towns, mountains or valleys," Obama said. "That is a task for the Afghan people."
The troop numbers Obama announced are largely in line with what military commanders have sought. His announcement indicates the longest war in American history - launched by President George W Bush following the 11 September 2001 al-Qaeda attacks - will end by the time he leaves office.
Mark Mardell, BBC News, Washington
Barack Obama is performing a balancing act. He's reminding the world why the US is in Afghanistan - because of the 9/11 attacks. He doesn't want people to say he's pulling out before the job is done. But he also wants to make it clear the war is winding down.
Leaving nearly 10,000 troops there at the beginning of next year is just about what the military wanted. But that number will be halved by the end of that year. And most will be gone by 2016.
Some will say he shouldn't predict any final numbers, but rely on what the top brass tell him at the time. We wait for the important West Point speech tomorrow but it is noticeable how much the president is focusing on the need to beat terrorism in other parts of the world - rather than the challenges posed by China and Russia.
He could be accused of fighting the last war. Perhaps he's just making sure the next one doesn't happen.
"We have to recognise Afghanistan will not be a perfect place - and it is not America's responsibly to make it one," Obama said. But he added the US would help Afghans secure a "hard-earned peace".
Obama acknowledged the length of the timetable for US involvement in Afghanistan: "I think Americans have learned it's harder to end wars than it is to begin them. Yet this is how wars end in the 21st Century."
Afghanistan's run-off election between Abdullah Abdullah and Ashraf Ghani to replace Karzai is set for 14 June.
Obama noted on Tuesday that both have said they would sign a security agreement with the US.
All British combat troops are due to leave by the end of this year.
At the weekend, President Obama paid a surprise visit to US troops in Afghanistan. On Monday at a Memorial Day ceremony he paid tribute to the more than 2,000 soldiers who have lost their lives in the country's longest war.