This followed months of negotiations in Qatar’s capital, Doha.
The agreement signed on Saturday was witnessed by leaders from Pakistan, India, Indonesia, Uzbekistan and Tajikistan.
The pact will pave the way for the United States to gradually withdraw its troops.
Mohammed Naeem, a Taliban representative in Doha, called the deal as “a step forward”.
“With this deal comes the end of war in Afghanistan,” he told Al Jazeera.
A joint statement by the US and the Afghan government said the US and NATO troops would withdraw from Afghanistan within 14 months.
“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,” it said.
Afghan government will also engage with the United Nations Security Council “to remove Taliban members from sanctions list by May 29”.