The United States signed a historic deal with the Taliban that could pave the way toward a full withdrawal of foreign soldiers from Afghanistan over the next 14 months and represent a step toward ending the 18-year-war there.

While the agreement paves the way for the United States to gradually pull out of its longest war, many expect that talks to come between the multiple Afghan sides will be far more complicated.

The deal was signed in the Qatari capital Doha by US special envoy Zalmay Khalilzad and Taliban political chief Mullah Abdul Ghani Baradar.

US Secretary of State Mike Pompeo was on hand to witness the ceremony.

US Defense Secretary Mark Esper meanwhile travelled to Kabul on a visit that officials and experts said was aimed at reassuring the Afghan government about the United States' commitment to the country.

For US President Donald Trump, the deal represents a chance to make good on his promise to bring U.S. troops home.

But security experts have also called it a foreign policy gamble that would give the Taliban international legitimacy.

"Today is a monumental day for Afghanistan," the US Embassy in Kabul said on Twitter. "It is about making peace and crafting a common brighter future. We stand with Afghanistan."

Hours before the deal, the Taliban ordered all its fighters in Afghanistan "to refrain from any kind of attack ... for the happiness of the nation."

"The biggest thing is that we hope the US remain committed to their promises during the negotiation and peace deal," said Zabiullah Mujahid, a spokesman for the hardline Islamist group.

He said it was "irritating and provocative" that foreign military aircraft continued to fly over Taliban territory, but militia fighters were following the order to stand-down.

For millions of Afghans, the deal represents some hope for an end to years of bloodshed.

"Peace is extremely simple and my country deserves it. Today is the day when maybe we will see a positive change," said Javed Hassan, a school teacher living on the outskirts of Afghan capital, Kabul.

Mr Hassan's children were killed in a bomb blast carried out by the Taliban in 2018.

Since then, he has been writing letters to world leaders urging them to end the Afghan war.

The US and the Taliban have agreed to swap thousands of prisoners in a "confidence building measure" as part of the deal

"Up to 5,000 prisoners of the (Taliban)... and 1,000 prisoners of the other side (Afghan forces) will be released by March 10," the deal said.

Dialogue between the Kabul government and the Taliban is due to begin by that date.

Earlier, Mr Esper said that the United States "will not hesitate to nullify" its historic deal with the Taliban if the insurgents renege on their security guarantees and commitment to hold talks with the Afghan government.

He warned warned that "should the Taliban fail to honour their commitments they will forfeit their chance to sit with fellow Afghans and deliberate on the future of their country.

"Moreover the United States would not hesitate to nullify the agreement," he added.

Yesterday, US President Donald Trump urged the Afghan people to embrace a chance for a new future.

With a one-week ceasefire set as a condition for the pact holding firm, Mr Trump said that there is now a possibility of ending the nearly two-decade war in Afghanistan.

The commitments to be made in the Taliban agreement and the joint declaration are an "important step to a lasting peace" that could free Afghans from the threat of al-Qaeda and the so-called Islamic State group, Mr Trump said in a statement.

"If the Taliban and the government of Afghanistan live up to these commitments, we will have a powerful path forward to end the war in Afghanistan and bring our troops home," he said.

Nevertheless, he added, "Ultimately it will be up to the people of Afghanistan to work out their future."

"We, therefore, urge the Afghan people to seize this opportunity for peace and a new future for their country."