The Taliban has released Australian academic Timothy Weeks and American colleague Kevin King, held captive for more than three years, as part of a hostage swap deal.
The two academics were abducted outside the American University in Kabul where they worked as teachers, in August 2016.
In exchange for their release on Tuesday, three ranking Taliban prisoners were freed by Kabul and flown to Qatar.
Late on Tuesday, Australian Prime Minister Scott Morrison said he was "profoundly pleased and relieved" Weeks, 50, and King, 63, had been let go by their kidnappers.
"The Australian government offers its deepest appreciation to President (Donald) Trump and the United States for their immeasurable assistance and co-operation, without which we would not be able to welcome Tim back," he said.
"We also convey our deepest appreciation to the government of Afghanistan led by President (Ashraf) Ghani for its invaluable assistance with this case over the past three years."
The release is understood to have taken place in the Naw Bahar district in southern Afghanistan, a region largely under Taliban control.
However 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.
Ghani a week ago announced the "conditional release" of the Taliban figures on state television.
Australia's Department of Foreign Affairs and Trade said earlier on Tuesday that decision had obviously been a difficult one but had been made by Ghani in good faith.
Morrison said he regarded the eventual release of the prisoners as "one of a series of confidence-building measures that are taking place in Afghanistan".
In 2017 Weeks and King featured in two Taliban-issued videos.
One in January depicted them as 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