KABUL/DOHA (Reuters) - The United States signed a deal with Taliban insurgents on Saturday that could pave the way toward a full withdrawal of foreign soldiers from Afghanistan and represent a step toward ending the 18-year-war in the nation.

But while the agreement creates a path for the United States to gradually pull out of its longest war, many expect the talks to come between the Afghan sides may be much more complicated.

The deal was signed in the Qatari capital Doha by U.S. special envoy Zalmay Khalilzad and Taliban political chief Mullah Abdul Ghani Baradar, with U.S. Secretary of State Mike Pompeo on hand to witness the ceremony.

U.S. Defense Secretary Mark Esper called the accord a good step but just the beginning.

“Achieving lasting peace in Afghanistan will require patience and compromise among all parties,” said Esper, who met Afghan President Ashraf Ghani in Kabul where they announced a joint declaration in parallel to the U.S.-Taliban accord.

The United States said it is committed to reducing the number of its troops in Afghanistan to 8,600 -- from the current 13,000 -- within 135 days of signing the deal, and working with its allies to proportionally reduce the number of coalition forces in Afghanistan over that period, if the Taliban adhere to their commitments.

A full withdrawal of all U.S. and coalition forces would occur within 14 months of the deal getting signed, if the Taliban hold up their end of the deal, the joint statement said.

“We are working to finally end America’s longest war and bring our troops back home,” said U.S President Donald Trump in a White House statement.

The accord represents a chance to make good on a longstanding promise to get troops out, as he seeks re-election in November. But security experts have also called it a foreign policy gamble that would give the Taliban international legitimacy.

Ghani said he hoped the Doha deal paves the way towards lasting peace, telling a news conference in Kabul:

“The nation is looking forward to a full ceasefire.”

The Afghan government said it stood ready to negotiate and conclude a ceasefire with the Taliban, and it affirmed its support for the phased withdrawal of U.S. and coalition forces subject to the Taliban’s fulfillment of its commitments.

It also said that it remained committed to preventing militant groups from using its soil to threaten the security of the United States, its allies and other countries.

Separately, NATO pledged to adjust the coalition troop levels in the first phase too, bringing down NATO’s numbers to about 12,000 from roughly 16,000 troops at present.

“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,” NATO Secretary-General Jens Stoltenberg, who was in Kabul on Saturday, told reporters.

HOPE FOR AN END TO BLOODSHED

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.”

Slideshow ( 19 images )

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

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, 38, a school teacher living on the outskirts of Afghan capital, Kabul.

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.

Slideshow ( 19 images )

SERIOUS CHALLENGES

The war, which has killed tens of thousands of people, began when the United States launched attacks on Afghanistan just weeks after the Sept. 11, 2001, attacks on New York and Washington by the Afghanistan-based al Qaeda militant group.

Washington accused the Taliban of harboring al Qaeda and its leader Osama bin Laden, and with its allies ousted the group from power. But the Taliban has remained a potent force and currently controls about 40% of Afghan territory.

The next step will be for negotiators to work out an agreement for comprehensive ceasefire and the future governance of the country.

Officials and experts say this will pose serious challenges as the Afghan government has until now been 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.

Under the deal, the Taliban wants 5,000 fighters to be released from Afghan-run jails, but it is not clear whether the Afghan government will agree.

Afghan National Security Advisor Hamdullah Mohib said in an interview with Tolo news channel that the Afghan government made no commitment to release 5,000 prisoners by March 10, a date stipulated in the deal.

Mohib also said the deal lacked clarity about the Taliban’s ties with Pakistan.

Afghanistan routinely accuses neighboring Pakistan of supporting Taliban militants. Pakistan denies doing so and in turn accuses Afghanistan of supporting militants fighting the Pakistani government.

There are also questions about whether Taliban fighters loyal to hardline Islamist splinter groups will be willing to adhere to the reduction in violence agreement.