The United States and the Taliban have agreed to sign a peace deal next week aimed at ending 18 years of war in Afghanistan and bringing US troops home, wrapping up America's longest-running conflict and fulfilling one of President Donald Trump's main campaign promises.

The planned February 29 signing depends on the success of a week-long nationwide "reduction in violence" agreement in which all sides have committed to end attacks.

It is due to start at midnight Friday local time (1930 GMT), according to an Afghan official who spoke on condition of anonymity because he was not authorised to talk to the media.

Suhail Shaheen, spokesman for the Taliban's political office in Doha, speaks to the media in Moscow, Russia in 2019. (AP)

The announcement follows months of negotiations between the two sides that have broken down before. Yet both parties have signalled a desire to halt the fighting that began with the US invasion after the September 11, 2001, attacks by Osama bin Laden's Afghanistan -based al-Qaida network.

Should the truce stand, the US-Taliban deal would be followed within 10 days by the start of all-Afghan peace talks that could result in the formation of a new government in Kabul, a pledge from the Taliban not to allow terrorist groups to operate in the country, and the phased withdrawal of US and other foreign troops over 18 months.

How the truce could reflect on Trump

The plan is a gamble for Mr Trump, who retweeted several news accounts of the agreement. If it's successful, he will be able to claim to have taken a first step toward meeting his 2016 campaign pledge to bring American troops home.

But if it fails, Mr Trump could be painted by his Democratic adversaries in an election year as being naïve and willing to sacrifice the security of US soldiers and American interests for the sake of political expediency.

For the Taliban, the successful completion of the truce and Afghanistan peace talks would give the group a shot at international legitimacy, which it lacked at the time it ran the country and gave bin Laden and his associates safe haven.

The truce, to be monitored by American forces, will likely be fragile and US officials have noted the possibility that "spoilers" uninterested in peace talks could disrupt it.

The United States and the Taliban have agreed to sign a peace deal next week aimed at ending 18 years of war in Afghanistan and bringing US troops home, wrapping up America's longest-running conflict and fulfilling one of President Donald Trump's main campaign promises. (AP)

Determining who is responsible for potential attacks during the seven days will therefore be critical.

Both sides were cautiously optimistic in announcing the agreement that had been previewed a week ago by a senior US official at an international security conference in Munich, Germany.

The announcement had been expected shortly thereafter but was delayed in part because of Monday's release of the results of Afghanistan's disputed September 2019 elections that showed President Ashraf Ghani winning by an extremely narrow margin.

What the US had to say

US Secretary of State Mike Pompeo said in a statement that the peace agreement, to be signed in Doha, Qatar, by US special envoy for Afghanistan Zalmay Khalilzad and Taliban representatives, will eventually lead to a permanent cease-fire.

The deal also envisions guarantees from the Taliban that Afghanistan will not be used to attack the US or its allies.

"We are preparing for the signing to take place on February 29," Mr Pompeo said.

"Intra-Afghan negotiations will start soon thereafter, and will build on this fundamental step to deliver a comprehensive and permanent ceasefire and the future political road map for Afghanistan."

US Secretary of State Mike Pompeo said in a statement that the peace agreement, to be signed in Doha, Qatar, by US special envoy for Afghanistan Zalmay Khalilzad and Taliban representatives, will eventually lead to a permanent cease-fire. (TASS)

The Taliban, meanwhile, said in a statement that the agreement is intended to achieve nationwide peace and end to the foreign troop presence in the country.

The statement said both sides "will now create a suitable security situation" ahead of the agreement signing date, invite international representatives to a signing ceremony, arrange for the release of prisoners, structure a path for peace talks, "and finally lay the groundwork for peace across the country with the withdrawal of all foreign forces".

The Taliban added that they will not allow "the land of Afghanistan to be used against security of others so that our people can live a peaceful and prosperous life under the shade of an Islamic system".

Why there might be conflict ahead

But the road ahead is fraught with difficulties, particularly as some Taliban elements and other groups have shown little interest in negotiations.

An attack that killed two Americans last September disrupted what at the time was an expected announcement of a peace deal.

And, it remained unclear who would represent Kabul at the intra-Afghan talks.

Mr Ghani's rivals have disputed the Afghan election commission's declaration that he won the presidential election.

The Taliban have refused to talk to Mr Ghani's government and also denounced the election results, saying they will talk to government representatives but only as ordinary Afghans, not as officials.

Germany and Norway have both offered to host the all-Afghan talks, but no venue has yet been set.