KABUL — An American and an Australian held hostage by the Taliban for the past three years were freed Tuesday, just hours after high-level militants were also released, U.S. and Afghan officials said, in a move officials hope will jump-start peace talks to end nearly two decades of war in Afghanistan.

American Kevin King, 63, and Australian Timothy Weeks, 50, were instructors at the American University of Afghanistan in Kabul when they were kidnapped in 2016. The three militants released are senior commanders of the Haqqani network, an Afghan insurgent group closely allied with the Taliban: Mali Khan, Hafiz Rashid and Anas Haqqani.

After their release Tuesday, King and Weeks were in the care of the U.S. military and would soon be reunited with relatives, Secretary of State Mike Pompeo said in a statement.

“The Taliban have indicated that the release of the two professors is intended as a goodwill gesture, which the United States welcomes,” Pompeo said. The statement also noted “the Taliban’s impending release of 10 Afghan prisoners,” who John R. Bass, the U.S. ambassador to Afghanistan, referred to in a tweet as members of the Afghan security forces.

A White House statement applauded King and Weeks’s release and said the men had “endured significant hardship during their captivity.”

They were freed in the southern province of Zabul, where an Afghan official said the handover was accompanied by a 48-hour cease-fire starting the night before. He spoke on the condition of anonymity because of the sensitivity of the matter.

Taliban spokesman Zabiullah Mujahid said the exchange was “good progress for building . . . goodwill and can aid the peace process.”

The three Haqqani militants, who were flown to Qatar after their release, had been held in a government detention center near Bagram air base. Khan was captured in 2011, and Rashid and Haqqani were arrested at the same time in 2014. Haqqani is a younger brother of the Taliban’s deputy leader and son of the Haqqani network’s founder.

The Haqqani network is accused of orchestrating sophisticated and deadly attacks against Afghan and foreign installations in recent years. It has been active in kidnapping foreigners and is believed to have seized King and Weeks. The U.S. government designated the network a terrorist organization in 2012.

The prisoner exchange was long sought by U.S. special envoy Zalmay Khalilzad, who shuttled between Pakistan and Afghanistan for weeks seeking a goodwill gesture to help restart peace talks with the Taliban.

Khalilzad had met with Taliban negotiators for nearly a year before a peace deal appeared imminent just months ago. But in early September, the effort was scuttled by a tweet from President Trump, who later declared the talks “dead.” Since then, informal discussions have attempted to keep the peace effort alive.

Ghani initially announced the prisoner swap on live television last week, saying it would help bring “peace and stability” to Afghanistan.

But days later, none of the prisoners had been freed. Afghan officials blamed the Taliban for the delay, and Taliban officials blamed the United States.

King and Weeks, the two professors held by the Taliban, were teaching English at the American University of Afghanistan, a private nonprofit institution in Kabul, when they were kidnapped. Over the course of their captivity, concerns mounted that their health was deteriorating. In October 2017, the Taliban issued a statement saying that King had heart and kidney disease and needed urgent medical attention.

On Monday night, Ghani discussed the swap with Pompeo and national security adviser Robert C. O’Brien. The conversation reviewed “the steps necessary to implement President Ghani’s recent decision to release the three high-level Taliban/Haqqani detainees,” the presidential palace in Kabul said in a statement.

“The U.S. officials reiterated their support for President Ghani’s decision and committed to work closely together to respond to any possible Taliban violence in the event the group doesn’t respond in good faith,” the statement added.

If peace talks restart, it is not clear whether they would pick up where the negotiators left off or begin from scratch. A draft peace deal included an agreement on the withdrawal of many American troops from Afghanistan in exchange for a Taliban pledge not to harbor terrorist groups. But Afghan government officials have said since then that a cease-fire or reduction in violence is necessary before a deal can be concluded.

Nicholas Kay, NATO’s civil chief for Afghanistan, hailed the release of the Taliban-allied prisoners.

“The decision to release conditionally three prisoners is a bold confidence-building step on the path to peace. Taliban should reciprocate & also reduce violence,” he said in a tweet.

In a statement Tuesday, King’s family thanked U.S. government officials for their efforts.

“We are so happy to hear that my brother has been freed and is on his way home to us,” King’s sister, Stephanie Miller, said in the statement. “This has been a long and painful ordeal for our entire family, and his safe return has been our highest priority.”

The American University of Afghanistan expressed relief about the release of King and Weeks. “We look forward to providing all the support we can to Kevin and Tim and their families,” a statement read. “We wish to extend our gratitude to all involved in the release of our colleagues.”

Pakistani Prime Minister Imran Khan also welcomed the release and indicated that his country, which borders Afghanistan, helped obtain their freedom. The Haqqani network is based in Pakistan.

“As part of the [international] community working to bring peace & end the suffering of the Afghan people, Pak has fully supported & facilitated this release,” Khan tweeted.

Trump has said freeing Americans held captive abroad is a top priority for his administration. But he also has criticized the 2014 exchange of five U.S.-held Taliban prisoners for Sgt. Bowe Bergdahl, who was a hostage. In more than a dozen tweets, he said it was a “BAD DEAL” and “stupid,” and called Bergdahl a “traitor.”

Hassan reported from Jalalabad, Afghanistan. Susannah George in Jalalabad contributed to this report.