Factbox: Agreement due to be signed by U.S. and Taliban in Doha

Afghan children celebrate in anticipation of the U.S-Taliban agreement to allow a U.S. troop reduction and a permanent ceasefire, in Jalalabad

(Reuters) - The planned signing on Saturday of an agreement between the United States and the Taliban has spurred hopes that it could lead to an end to almost two decades of conflict in Afghanistan that has killed thousands and become America's longest war.

Below are the key details.

What is the agreement?

- The agreement is due to be signed in Qatar's capital Doha, the Taliban's political headquarters and the host for talks over the past year and a half.

- Senior Taliban leaders will take part along with U.S. Special Envoy for Afghanistan Zalmay Khalilzad and U.S. Secretary of State Mike Pompeo. Pakistan's foreign minister Shah Mehmood Qureshi will also attend. A delegation of junior ministers from the Afghan government are also in Doha. U.S. Defence Secretary Mark Esper and NATO Secretary General Jens Stoltenberg will visit the Afghan capital Kabul on Saturday to coincide with the signing.

- The agreement will lay the groundwork for negotiations between the Taliban and the Afghan government - known as intra-Afghan talks - to end a war that began after U.S.-led forces invaded Afghanistan following the 9/11 attacks in 2001.

- Saturday's deal is expected to set out a timeline for the pullout of thousands of U.S. troops in exchange for guarantees from the Taliban not to allow militant groups such as al-Qaeda to operate in Afghanistan.

What will happen next?

- The U.S.-Taliban agreement would begin a phased withdrawal of American and coalition forces and also require the Taliban to initiate a formal dialogue with the Afghan government and other political and civil society groups on a permanent nationwide ceasefire and power-sharing in post-war Afghanistan.

- Bringing back troops from America's longest war could be a political coup for U.S. President Donald Trump in the 2020 U.S. election campaign.

-However, it is unclear how long it could take for the United States to withdraw its roughly 12,000 to 14,000 troops and about 8,500 soldiers from 37 nations serving as part of a mission to train, advise and assist Afghan forces.

-Under the agreement, Western powers could continue to maintain military bases in the land-locked country that shares borders with six nations.

- Taliban commanders say once the deal is signed the group will release 1,000 Afghan prisoners. In exchange, the Taliban expects the Afghan government to release their 5,000 fighters.

- The next step would be for negotiators to work out an agreement for the future of the country, including how it will be governed and what role the Taliban would have.

- Officials and experts say that will pose serious challenges. So far, negotiations have been between the United States and the Taliban and President Ashraf Ghani's government in Kabul has complained of being sidelined.

- Even before getting to talks with the Taliban, Afghanistan's two main political rivals, Ghani and Chief Executive Abdullah Abdullah, must settle a dispute over which officials, opposition members and activists should negotiate with the insurgents.

- That process was further complicated last month by competing victory claims by Ghani and Abdullah in a disputed Sept. 28 election

How did the agreement come about?

- The prospect of a peace arrangement with the Taliban has been raised by Afghan and U.S. leaders for more than a decade. Momentum towards the latest deal came after Trump appointed Afghan origin diplomat Khalilzad as his special envoy to Afghanistan.

- Khalilzad has held talks with the Taliban in Doha and travelled to Pakistan several times to meet key Taliban leaders. Progress had stalled several times, most notably in September when Trump tweeted that he had cancelled talks after an attack in Kabul that killed 12, including an American soldier.

- Talks began again in late 2019, culminating in a seven-day 'reduction in violence' agreement that ends on Saturday with the signing of the deal in Doha.

(Reporting by Charlotte Greenfield, Editing by Rupam Jain and Ed Davies)