The Taliban have released an American and an Australian held hostage since 2016 in exchange for three prominent members of the militant group who were set free by the Afghan government and flown to Qatar the previous day.

Australian Timothy Weeks, 50, and Kevin King, 63, an American, were handed over to US forces in southern Zabul province and transported from the area by helicopter, putting an end to more than three years in captivity.

The prisoner swap was supposed to have taken place last week but was aborted for reasons that are still unclear.

The release of the two westerners, who were teachers at Kabul’s American University of Afghanistan, was confirmed on Tuesday by Taliban officials and by Imran Khan, the prime minister of Pakistan, who said his government had helped to facilitate the exchange.

King’s family issued a statement saying he was safe with US officials in Afghanistan and getting the medical care he needed ahead of his return home to be reunited with his family. It was not clear if Weeks was also with Australian officials.

“We are so happy to hear that my brother has been freed and is on his way home to us,” said King’s sister, Stephanie Miller. “This has been a long and painful ordeal for our entire family, and his safe return has been our highest priority. We appreciate the support we have received and ask for privacy as we await Kevin’s safe return.”

On Wednesday morning Australian time the Weeks family released a statement thanking the Australian, US and Afghan governments for their role in securing his release, and asking for privacy.

“Our family is overjoyed that Tim has been released after more than three years in captivity,” the statement said. “We thank our friends and extended family for their love and support over the past three years during this very difficult time.

“While we understand the intense public interest in Tim’s release, we do not want to comment further. We ask that the media respect both our and Tim’s privacy. It is important that Tim now be given the time and space to start to come to terms with his experience.”

The Australian prime minister, Scott Morrison, said he was “profoundly pleased and relieved” at the news that Weeks was free. “Tim’s family has asked for privacy,” Morrison said on Twitter. “They have asked the Australian government to convey their relief that their long ordeal is over, and their gratitude to all those who have contributed to Tim’s safe return.”

The three released Taliban prisoners include Anas Haqqani, the younger brother of the militant group’s deputy, Sirajuddin Haqqani, who is also head of the hardline Haqqani network.

The Afghan president, Ashraf Ghani, announced the “conditional release” of the Taliban figures at a press event broadcast live on state television last week. He said it was a hard decision but one he felt compelled to make in the interest of the Afghan people.

The swap had been expected to take place within hours of Ghani’s announcement but diplomats soon flagged a problem, and after two days a Taliban spokesman said the group had yet to receive its prisoners. The reasons for the delay – and for the apparent resumption of the deal on Tuesday – are unclear.

Weeks, from the New South Wales town of Wagga Wagga, and King, from Pennsylvania, were abducted at gunpoint from a car in August 2016. They were seized outside the American University in Kabul where they both worked as teachers.

US Navy Seals conducted a raid to free them days later, descending on a militant hideout in the mountains of eastern Afghanistan, but the men had been moved hours earlier, according to reports.

The pair appeared looking gaunt and weathered in a video released in January 2017 begging their parents to ask the US government to negotiate for their release.

They appeared in a second video later that year, setting a June 2017 deadline for their release, in which Weeks pleaded with the then Australian prime minister Malcolm Turnbull to negotiate for his release.

Both men said they were being treated well by the Taliban but that they would remain prisoners unless their governments could negotiate their freedom. It is unknown whether the men had been forced to speak.

The Taliban released a statement in October of that year claiming King was suffering from a “dangerous heart and kidney disease”.

“We have tried to treat him from time to time, but we do not have medical facilities as we are in a war situation,” the Taliban statement said.

A Taliban commander in eastern Afghanistan previously told the Guardian the group considered teachers at the American University of Afghanistan dangerous as they “change the minds of society”.

Khan said Pakistan welcomed the release of the men and hoped it would give “a boost of confidence to all parties involved to re-engage in the peace process”.

The American University of Afghanistan said in a statement it “shares the relief of the families of Kevin and Timothy, and we look forward to providing all the support we can to Kevin and Tim and their families”.

Southern Zabul province, where the two professors were freed, is heavily controlled by the Taliban and vast parts of it have long been a no-go area for the government.

According to the Taliban, an unofficial ceasefire is being observed in three districts of the province – Shahjoy, Shahmatzo and Naw Bahar – possibly to facilitate the release of the two hostages.

The Haqqani group predates the Taliban but has become integrated into its structure, and is suspected of having carried out some of the most brutal and indiscriminate attacks over the course of the nearly two decades of war that have followed the 2001 US-led invasion.

Besides a statement in 2017 saying that the Australian government was “working to secure the release of an Australian man in Afghanistan”, very little has been said publicly, and no public campaigns by the family or otherwise have been made regarding their cases.

The US secretary of state, Mike Pompeo, and the US national security adviser, Robert O’Brien, made separate calls to Ghani on Monday to discuss the prisoners’ release, Ghani’s spokesman, Sediq Sediqqi, said.

The release and swap were intended to try to restart talks to end Afghanistan’s 18-year war and allow for the eventual withdrawal of US troops from Afghanistan.

The US had been close to an agreement with the Taliban in September but a fresh wave of violence in the Afghan capital in which a US soldier died brought talks and any impending deal to a halt.

The agreement was to call for direct talks between the Taliban and Afghan government as well as other prominent Afghans to find a negotiated end to the war and to set out a roadmap for a peaceful post-conflict Afghanistan.

Associated Press contributed to this report.