"US troops as well as forces deployed by our NATO allies and operational partners will be out of Afghanistan before we mark the 20th anniversary of that heinous attack on 11 September," US President Joe Biden announced on Wednesday.
"It's time to end America's longest war. It's time for American troops to come home," he said.
Washington's NATO allies will follow the US out of Afghanistan.
NATO countries and partners will start withdrawing their remaining 10,000 troops by 1 May and will wrap up this process "within a few months," according to a joint statement from the alliance's foreign and defence ministers.
No mention was made of the September deadline cited by Biden, however.
Germany, the second-biggest contributor of troops to the NATO mission after the US, could withdraw its troops by mid-August. The country's defence minister Annegret Kramp-Karrenbauer told lawmakers from specialist parliamentary groups about the plans in a Wednesday phone briefing, several participants told dpa.
More than 30 nations contribute soldiers to the NATO mission. There are around 2,500 US soldiers and 1,000 German troops left in the country. At the mission's peak, some 100,000 soldiers were stationed in Afghanistan.
Earlier, Afghan President Ashraf Ghani said he had spoken to Biden about the US forces' withdrawal.
"The Islamic Republic of Afghanistan respects the US decision and we will work with our US partners to ensure a smooth transition," Ghani tweeted.
He added that Afghan forces were "fully capable of defending its people and country."
The historic decision comes almost 20 years after a US invasion that was a response to the 11 September 2001 terrorist attacks.
What began as an effort to overthrow the Taliban regime - which had provided support and shelter to the terrorists who planned the attack - became the longest war Washington has ever waged.
Biden is the fourth US leader to preside over American troops' presence in Afghanistan.
No longer a 'combat mission'
NATO's mission there is no longer a combat one, but rather supports Afghanistan's internationally backed and democratically elected government by training and advising security forces in their fight against Islamist extremists including the Taliban.
Over the years, the conflict has claimed the lives of tens of thousands of civilians plus Afghan and foreign fighters, and cost hundreds of billion of dollars.
Former US president Donald Trump struck a deal with the Taliban last year, agreeing to withdraw all US and international troops from Afghanistan by 1 May, leaving Biden little room to manoeuvre on the future of the mission.
Wednesday's announcement of an unconditional withdrawal was met with a mixed response in Afghanistan. The former head of Afghanistan's independent human rights commission Sima Samar called the move "unfortunate."
An Afghan peace negotiator went further. "It is the most irresponsible, selfish thing the United States could do to its Afghan partners," the source, who wished not to be named, said.
The negotiator said it might be the end of the war for Washington, but that Afghan partners will pay the price.
"They could have ended this in a responsible way, with a little more patience," they said.
The Taliban has previously threatened consequences if the withdrawal doesn't go ahead as agreed under Trump.
For the NATO allies and the Afghan government, the main fear is that the group could regain significant control over Afghan territory once foreign troops are gone, or that the country could slip into civil war.
Afghanistan is highly dependent on its foreign military allies for training and logistics and intelligence support.
Pulling out also risks jeopardizing the gains made on education, health and women's rights.
'Support' for Afghan people
"This is not an easy decision, and it entails risk," NATO Secretary General Jens Stoltenberg told reporters in Brussels alongside the US secretaries of state and defence.
But the mission had served its original goal of stopping Afghanistan from serving as a safe haven for those plotting international terror attacks, the alliance chief said.
US Secretary of State Antony Blinken said NATO and the US "will continue to invest in and support the Afghan people and their chosen leaders."
"We will also remain vigilant against any possibility that the threat of terrorism re-emerges in Afghanistan," he added.
Ahead of Biden's official announcement, the Taliban reiterated its call for the withdrawal of all foreign forces from Afghanistan by 1 May. The Taliban movement, which still controls roughly 10 per cent of Afghanistan, has continued carrying out attacks in different parts of the country despite ongoing peace talks.
Since last September, the radical Islamist movement's representatives have been holding peace negotiations with envoys of the Afghan government in Qatar but progress has stalled.
A US-initiated international conference on Afghanistan is set to begin in Istanbul on 24 April, according to the Turkish Foreign Ministry.
The aim of the high-level meeting is to complement the talks happening in Doha and get the peace process on a faster track.
Earlier this week, the Taliban said they would not take part in a planned peace conference for Afghanistan until all international troops have withdrawn from the country completely.