KABUL, Afghanistan — Afghanistan and the Taliban have reached a deal to release two American University teachers, including a U.S. citizen, in exchange for three Taliban members, the Afghan president said Tuesday.

American Kevin King, who was abducted by the insurgents in Afghanistan in August 2016. EL-EMARA Taliban via AP file

In a live address on national television, President Ashraf Ghani said that the prisoner exchange would free two American University professors — U.S. citizen Kevin King and Australian citizen Timothy Weeks. The two were kidnapped at gunpoint from the American University of Afghanistan in Kabul in August 2016.

Taliban commanders Anas Haqqani, Haji Maali Khan and Hafiz Rasheed Ahamd Omari are also set to be released in exchange, the president said.

Ghani said the three Taliban captives were kept in a Bagram prison, which is under the control of the Afghan government and is a facility where some of the most high-profile prisoners are kept, after they were captured outside Afghanistan.

Taliban leaders and members of the Haqqani group confirmed to NBC News that three of their prisoners were freed in exchange for two American University teachers Tuesday.

The Taliban said the trio were flown to Qatar in a special plane from Kabul airport.

Their release was "widely celebrated," a member of the Haqqani network said.

The American University of Afghanistan said in a statement that it “is encouraged to hear reports of the possible release of our two colleagues, Kevin King and Timothy Weeks.”

"While AUAF is not part of these discussions, we continue to urge the immediate and safe return of our faculty members who have been held in captivity, away from their friends and families, for more than three years," the university said.

Ghani said in his speech that Afghan authorities were aware that the health of the western prisoners was deteriorating in custody and their release was one of the unconditional demands in peace negotiations with the Taliban.

The release of the prominent insurgents was a "difficult, but necessary decision," intended to show the willingness of Afghanistan's government for peace talks, the president said.

It was also a decision that was made after consultation with the international community and the United States, he added.

The announcement comes as efforts are being made to revamp peace talks between the U.S. and the Taliban.

In January, senior Taliban officials said that peace talks with the U.S. had stalled after the American delegation demanded that the militant group announce a cease-fire and release King.

A Taliban commander at that time called the alleged demand “unrealistic.” The Taliban had said that King was seriously ill.

In September, President Donald Trump announced he was canceling "peace negotiations" with the Taliban leadership after a U.S. service member was killed in a suicide attack in Kabul.

Trump tweeted at the time that he had been scheduled to hold a secret meeting at Camp David with Taliban leadership and, separately, the Afghan president.

The peace talks have been aimed at ending the United States’ longest war.

Taliban fighters have been battling U.S., NATO and Afghan government forces since they were toppled in 2001 after their government sheltered 9/11 mastermind Osama bin Laden.

Around 11,000 of them are currently in the Afghan government's custody, Ghani said during his televised address.

President Barack Obama announced the formal end of the U.S. combat mission in Afghanistan in December 2014, but about 13,000 U.S. forces remain in the country to train, advise and assist Afghan forces under a NATO mission.

Anas Haqqani is the son of Jalaluddin Haqqani, who founded the Haqqani terror network under his name in the 1970s and is said to have died after an illness in 2018. Anas Haqqani has been in Afghan custody since October 2014 when U.S. security forces nabbed him while en route to Qatar from Bahrain.

Last year, his name topped the list of those the Taliban said must be released, according to Taliban officials at the time.

The Haqqani network held Sgt. Bowe Bergdahl captive for five years. In 2014, the Taliban obtained five top commanders in exchange for the U.S. soldier in a deal with the U.S. that was brokered by Qatar.

A U.S. military judge in 2017 spared Bergdahl from prison for walking off his post in Afghanistan in 2009, sentencing him to a dishonorable discharge and a reduction in rank but no time behind bars. He pleaded guilty to desertion and misbehavior before the enemy.

Ahmed Mengli reported from Kabul, Afghanistan, Mushtaq Yusufzai from Peshawar, Pakistan, and Phil Helsel from Los Angeles.