Media playback is unsupported on your device Media caption Trump: "It's been a hard journey for everybody"

President Trump says it is "time to bring our people back home" after the US signed a deal with the Taliban aimed at bringing peace to Afghanistan.

Mr Trump said 5,000 US troops would leave Afghanistan by May and he would meet Taliban leaders in the near future, without specifying where.

The US and Nato allies have agreed to withdraw all troops within 14 months if the militants uphold the historic deal.

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.

The US invaded Afghanistan weeks after the September 2001 attacks in New York by al-Qaeda, then based in Afghanistan. The Taliban were ousted from power but became an insurgent force that by 2018 was active in more than two-thirds of the country.

More than 2,400 US troops have been killed during the conflict. About 12,000 are still stationed in the country.

What else did Trump say about the deal?

Speaking at the White House, Mr Trump congratulated Secretary of State Mike Pompeo, Defense Secretary Mark Esper and "the people of the United States for having spent so much in terms of blood, in terms of treasure, and treasury."

He said the Taliban had been trying to reach an agreement with the US for a long time, and that he had faith in the deal because "everyone is tired of war."

The president added that 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," he added. "If bad things happen, we'll go back with a force like no-one's ever seen."

What happened in Doha?

The deal was signed by US special envoy Zalmay Khalilzad and Taliban political chief Mullah Abdul Ghani Baradar with Mr Pompeo as a witness.

In a speech, Mr Pompeo urged the militant group to "keep your promises to cut ties with al-Qaeda".

Media playback is unsupported on your device Media caption The United States and the Taliban mark the signing of their agreement in Doha.

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.

Afghanistan's government did not take part in the US-Taliban talks, but said it was ready to negotiate with the Taliban.

What's in the agreement?

In addition to withdrawing US and allied troops, 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."

Media playback is unsupported on your device Media caption Zan TV presenter Ogai Wardak: "If the Taliban come, I will fight them"

A cautious peace for Afghanistan

By Secunder Kermani, BBC News, Kabul

US, Afghan and Taliban officials have all been careful to avoid calling today's agreement in Doha "a peace deal." But in Afghanistan, a sense of cautious optimism has been rising.

The Afghan war has been a bloody stalemate for years now, with the Taliban increasingly controlling or contesting more territory, yet unable to capture and hold major urban centres.

With this has come a growing realisation - by both the Taliban and the US - that neither side is capable of an outright military victory.

This deal now opens the door to wide-ranging talks between the militants and Afghan political leaders.

But these discussions will be much more challenging - somehow there will have to be a reconciliation between the Taliban's vision of an "Islamic Emirate" and the democratic modern Afghanistan that has been created since 2001.

The priority for many ordinary Afghans, at least in the short term, is a substantive reduction in violence. We'll find out in the coming weeks, when the warmer spring weather generally heralds the start of "fighting season", if that will happen.

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"

Donald Trump's former National Security Adviser, John Bolton, has criticised the deal, and said it endangered American lives by "legitimising" the Taliban

How did US-Taliban talks come about?

Since 2011, Qatar has hosted Taliban leaders who have moved there to discuss peace in Afghanistan. It has been a chequered process. A Taliban office was opened in 2013, and closed the same year amid rows over flags. Other attempts at talks stalled.

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.

Media playback is unsupported on your device Media caption The view from Lashkar Gah province on whether peace with the Taliban is possible

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.

Media playback is unsupported on your device Media caption Tens of thousands of Afghan soldiers have been killed and injured. This is their story

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.