The US and the Taliban have signed an "agreement for bringing peace" to Afghanistan after more than 18 years of conflict.
The US and Nato allies have agreed to withdraw all troops within 14 months if the militants uphold the deal.
President Trump said it had been a "long and hard journey" in Afghanistan. "It's time after all these years to bring our people back home," he said.
Talks between the Afghan government and the Taliban are due to follow.
Under the agreement, the militants also agreed not to allow al-Qaeda or any other extremist group to operate in the areas they control.
Speaking at the White House, Mr Trump said the Taliban had been trying to reach an agreement with the US for a long time.
He said US troops had been killing terrorists in Afghanistan "by the thousands" and now it was "time for someone else to do that work and it will be the Taliban and it could be surrounding countries".
"I really believe the Taliban wants to do something to show we're not all wasting time," Mr Trump added. "If bad things happen, we'll go back with a force like no-one's ever seen."
The US invaded Afghanistan weeks after the September 2001 attacks in New York by the Afghanistan-based al-Qaeda group.
More than 2,400 US troops have been killed during the conflict. About 12,000 are still stationed in the country. President Trump has promised to put an end to the conflict.
What happened in Doha?
The deal was signed by US special envoy Zalmay Khalilzad and Taliban political chief Mullah Abdul Ghani Baradar with US Secretary of State Mike Pompeo as a witness.
In a speech, Mr Pompeo urged the militant group to "keep your promises to cut ties with al-Qaeda".
Mr Baradar said he hoped Afghanistan could now emerge from four decades of conflict.
"I hope that with the withdrawal of all foreign forces from Afghanistan the Afghan nation under an Islamic regime will take its relief and embark on a new prosperous life," he said.
Meanwhile US Defence Secretary Mark Esper was in the Afghan capital Kabul alongside Afghanistan's President Ashraf Ghani - whose government did not take part in the US-Taliban talks.
Mr Esper said: "This is a hopeful moment, but it is only the beginning. The road ahead will not be easy. Achieving lasting peace in Afghanistan will require patience and compromise among all parties." He said the US would continue to support the Afghan government.
Mr Ghani said the country was "looking forward to a full ceasefire". The government said it was ready to negotiate with the Taliban.
What's in the agreement?
Within the first 135 days of the deal the US will reduce its forces in Afghanistan to 8,600, with allies also drawing down their forces proportionately.
The move would allow US President Donald Trump to show that he has brought troops home ahead of the US presidential election in November.
The deal also provides for a prisoner swap. Some 5,000 Taliban prisoners and 1,000 Afghan security force prisoners would be exchanged by 10 March, when talks between the Taliban and the Afghan government are due to start.
The US will also lift sanctions against the Taliban and work with the UN to lift its separate sanctions against the group.
In Kabul, activist Zahra Husseini said she feared the deal could worsen the situation for women in Afghanistan.
"I don't trust the Taliban, and remember how they suppressed women when they were ruling," the 28-year-old told AFP.
"Today is a dark day, and as I was watching the deal being signed, I had this bad feeling that it would result in their return to power rather than in peace."
Landmark deal rife with uncertainties
This historic deal has been years in the making, as all sides kept seeking advantage on the battlefield.
The agreement is born of America's determination to bring troops home and a recognition, at least by some Taliban, that talks are the best route to return to Kabul.
It's a significant step forward, despite deep uncertainty and scepticism over where it will lead. When the only alternative is unending war, many Afghans seem ready to take this risk for peace.
Taliban leaders say they've changed since their harsh rule of the 1990s still seared in the memory of many, and most of all Afghan women.
This process will test the Taliban, but also veteran Afghan leaders of the past, and a new generation which has come of age in the last two decades and is hoping against hope for a different future.
What reaction has there been?
- UN Secretary-General Antonio Guterres stressed "the importance of sustaining the nationwide reduction in violence, for the benefit of all Afghans"
- Nato Secretary-General Jens Stoltenberg: "We went in together in 2001, we are going to adjust [troop levels] together and when the time is right, we are going to leave together, but we are only going to leave when conditions are right"
- UK Defence Secretary Ben Wallace: "I welcome this small but important step towards the chance for Afghans to live in peace, free from terrorism... We remain absolutely committed to building an Afghanistan that is a strong partner for decades to come"
How did US-Taliban talks come about?
In December 2018, the militants announced they would meet US officials to try to find a "roadmap to peace". But the hard-line Islamist group continued to refuse to hold official talks with the Afghan government, whom they dismissed as American "puppets".
Following nine rounds of US-Taliban talks in Qatar, the two sides seemed close to an agreement.
Washington's top negotiator announced last September that the US would withdraw 5,400 troops from Afghanistan within 20 weeks as part of a deal agreed "in principle" with Taliban militants.
Days later, Mr Trump said the talks were "dead", after the group killed a US soldier. But within weeks the two sides resumed discussions behind the scenes.
A week ago the Taliban agreed to a "reduction of violence" - although Afghan officials say at least 22 soldiers and 14 civilians have been killed in Taliban attacks over that period.
What's the background to the Afghan war?
It began when the US launched air strikes one month following the 11 September 2001 attacks and after the Taliban had refused to hand over the man behind them, Osama bin Laden.
The US was joined by an international coalition and the Taliban were quickly removed from power. However, they turned into an insurgent force and continued deadly attacks, destabilising subsequent Afghan governments.
The international coalition ended its combat mission in 2014, staying only to train Afghan forces. But the US continued its own, scaled-back combat operation, including air strikes.
The Taliban has however continued to gain momentum and in 2018 the BBC found they were active across 70% of Afghanistan.
Nearly 3,500 members of the international coalition forces have died in Afghanistan since the 2001 invasion.
The figures for Afghan civilians, militants and government forces are more difficult to quantify. In a February 2019 report, the UN said that more than 32,000 civilians had died. The Watson Institute at Brown University says 58,000 security personnel and 42,000 opposition combatants have been killed.
Why has the war lasted so long?
There are many reasons for this. But they include a combination of fierce Taliban resistance, the limitations of Afghan forces and governance, and other countries' reluctance to keep their troops for longer in Afghanistan.
At times over the past 18 years, the Taliban have been on the back foot. In late 2009, US President Barack Obama announced a troop "surge" that saw the number of American soldiers in Afghanistan top 100,000.
The surge helped drive the Taliban out of parts of southern Afghanistan, but it was never destined to last for years.
The BBC World Service's Dawood Azami says there are five main reasons the war is still going on now. They include:
- a lack of political clarity since the invasion began, and questions about the effectiveness of the US strategy over the past 18 years
- the fact each side is trying to break what has become a stalemate - and that the Taliban have been trying maximise their leverage during peace negotiations
- an increase in violence by Islamic State militants in Afghanistan - they've been behind some of the bloodiest attacks recently
There's also the role played by Afghanistan's neighbour, Pakistan.
There's no question the Taliban have their roots in Pakistan, and that they were able to regroup there during the US invasion. But Pakistan has denied helping or protecting them - even as the US demanded it do more to fight militants.