The Taliban has released Australian academic Timothy Weeks and American colleague Kevin King as part of a hostage swap deal, sources say.
The two academics were abducted in 2016 outside the American University in Kabul where they worked as teachers.
In exchange for their release, three ranking Taliban prisoners have been released by Kabul and flown to Qatar.
"The two professors are safely freed and are being taken care of now," according to an official speaking on condition of anonymity on Tuesday.
The release is understood to have taken place in the Now Bahar district, a region largely under Taliban control.
It wasn't immediately known if the two hostages were handed over to Afghan government representatives, intermediaries or US forces.
Their freedom came hours after the Afghan government freed the three Taliban prisoners. They included Anas Haqqani, the younger brother of Taliban deputy Sirajuddin Haqqani who also leads the fearsome Haqqani network.
It appears the Taliban had refused to hand over the two professors until they received proof their men had reached Qatar.
Afghan President Ashraf Ghani a week ago announced the "conditional release" of the Taliban figures on state television.
Australia's Department of Foreign Affairs and Trade said on Tuesday evening the decision had obviously been a difficult one but had been made by Ghani in good faith.
The government was again calling on the Taliban to release Weeks and King, a spokesman said.
"The Australian government has never stopped pressing for their release but we will not give a running commentary," he added.
In 2017 Weeks and King featured in two Taliban-issued videos.
One in January depicted them pale and gaunt, while in the later, the two men looked healthier and said a deadline for their release was set for June that year.
Both said they were being treated well but remained prisoners and appealed to their governments to help set them free. It was impossible to know whether they were forced to speak.
US officials subsequently said American forces had launched a rescue mission but the captives were not found at the raided location.
Secretary of State Mike Pompeo and National Security Adviser Robert O'Brien made separate calls to Ghani on Monday to discuss the prisoners' release.
The swap was intended to try to restart talks to end Afghanistan's 18-year war and allow for the eventual withdrawal of US troops from Afghanistan.
Australian Associated Press