American Kevin King and Australian Timothy Weeks were kidnapped in August 2016 from outside the American University of Afghanistan in Kabul where both worked as professors. They were freed in return for the release of three Taliban commanders under a swap that had been long delayed, the officials said.
The U.S.-backed government's decision to carry out the swap is seen as key to securing direct talks with the Islamist militants, who have, until now, refused to engage with what they call an illegitimate "puppet" regime in Kabul.
Talks between the Taliban and the United States aimed at ending their 18-year war collapsed in September after President Donald Trump called off what he described as a planned meeting at his Camp David presidential retreat.
"The two professors are safely freed and are being taken care of now," said a senior Afghan official on condition of anonymity because he was not authorized to speak to the media.
He did not provide further details.
Earlier on Tuesday, three Taliban sources familiar with the deal, including one in Qatar, home to the political leadership of the Afghan Taliban, said the three Taliban commanders who are part of the swap were freed from jail in Afghanistan.
"Soon after their release, they were flown to Doha and handed over to the political office in Qatar," said a Taliban leader in Afghanistan, who declined to be identified because he is not authorized to speak publicly about the deal.
Australian Prime Minister Scott Morrison confirmed the release of weeks.
"We regard this release as one of a series of confidence-building measures that are taking place in Afghanistan," Morrison said in a joint statement with his foreign minister. "We hope that such measures will set the stage for a ceasefire and intra-Afghan dialog."
Spokesmen for the Afghan government and the United States embassy in Kabul were not immediately available for comment.
On Nov. 12, President Ashraf Ghani said Afghanistan would free Anas Haqqani, a senior figure in the eponymous Haqqani network, a militant faction of the Taliban responsible for some of the worst violence in recent years, and two other Taliban commanders.
But the swap was abruptly postponed, with the Taliban then shifting their hostages to a new location.
The Haqqani network has in recent years carried out large-scale attacks on Afghan civilians. It is believed to be based in Pakistan and is part of the Taliban in Afghanistan.
King and Weeks were last seen in a 2017 hostage video looking disheveled and pleading with their governments to secure their release.
The prisoner exchange could help nudge forward efforts to end the Afghan war.
The United States and the Taliban were for most of the past year discussing a plan for the withdrawal of U.S. troops in exchange for Taliban security guarantees.
But Trump halted the talks following the death of a U.S. soldier and 11 other people in a Taliban bomb attack in Kabul.Before the talks were broken off, the United States and the Taliban both said they were close to reaching a deal.