Doha, Qatar - US officials and Taliban representatives have signed an agreement after months of negotiations in Qatar's capital that is aimed at ending the United States's longest war, fought in Afghanistan since 2001.

Saturday's agreement, signed in Doha in the presence of leaders from Pakistan, Qatar, Turkey, India, Indonesia, Uzbekistan and Tajikistan, will pave the way for the US to gradually withdraw its troops.

More:

The two sides have long wrangled over the US demand for a ceasefire before the signing of the agreement, which has four points: a timeline of 14 months for the withdrawal of all US and NATO troops from Afghanistan; a Taliban guarantee that Afghan soil will not be used as a launchpad that would threaten the security of the US; the launch of intra-Afghan negotiations by March 10; and a permanent and comprehensive ceasefire.

In a statement, the Taliban said it had reached an agreement "about the termination of occupation of Afghanistan".

"The accord about the complete withdrawal of all foreign forces from Afghanistan and never intervening in its affairs in the future is undoubtedly a great achievement," it added.

Earlier on Saturday, the Taliban ordered all its fighters to halt fighting and "refrain from attacks".

Mohammed Naeem, a Taliban representative in Doha, described the agreement as "a step forward".

"With this deal comes the end of war in Afghanistan," he told Al Jazeera.

For his part, US Secretary of State Mike Pompeo called on the Taliban to honour its commitments.

"I know there will be a temptation to declare victory, but victory for Afghans will only be achieved when they can live in peace and prosper," he said at the Doha ceremony.

The ceremony in Doha was attended by many international delegates [Sorin Furcoi /Al Jazeera]

Troop withdrawal

Minutes before the agreement was signed, a joint statement released by the US and the Afghan government said the US and NATO troops would withdraw from Afghanistan within 14 months.

About 14,000 US troops and approximately 17,000 troops from 39 NATO allies and partner countries are stationed in Afghanistan in a non-combatant role.

"The United States will reduce the number of US military forces in Afghanistan to 8,600 and implement other commitments in the US-Taliban agreement within 135 days of the announcement of this joint declaration and the US-Taliban agreement," the joint statement said.

It added that the Afghan government will engage with the United Nations Security Council "to remove Taliban members from sanctions list by May 29".

"No agreement is perfect, and the US-Taliban deal is no exception," said Robert Malley, president and CEO of the International Crisis Group.

"But it represents the most hopeful step to end a war that has lasted two decades and taken countless American and especially Afghan lives. It ought to be celebrated, bolstered and built upon to reach a genuine intra-Afghan peace."

Zalmay Khalilzad, US envoy for reconciliation in Afghanistan [Sorin Furcoi/Al Jazeera]

The talks were launched in 2018 as part of a push by US President Donald Trump's administration to strike a deal with the Taliban, which has been fighting the US-led forces in Afghanistan since it was toppled from power in 2001.

The agreement also proposes an intra-Afghan dialogue with the government in Kabul and the release of 5,000 Taliban members from prison.

The Taliban has so far refused to speak to the Western-backed Afghan government, saying it is a "puppet regime".

The intra-Afghan talks are to begin on March 10 but no specific details have been given.

A weeklong "reduction in violence" between the Taliban, the US and Afghan security forces saw a sudden drop in violence and casualties across the country after taking effect on February 22.

The Taliban now controls or holds influence over more Afghan territory than at any point since 2001 and has carried out near-daily attacks against military outposts throughout the country.

The two sides were on the verge of signing a peace agreement in September when Trump abruptly cancelled the talks after a Taliban attack killed an American soldier.

Trump has long expressed eagerness to bring US soldiers home and to end the country's longest war as he seeks re-election in 2020.

More than 100,000 Afghans have been killed or wounded since 2009 when the UN Assistance Mission in Afghanistan began documenting casualties.