An American woman, her Canadian husband and their three young children have been released after five years as captives of an armed group with ties to the Afghan Taliban, American and Pakistani officials say.

US officials said on Thursday that Pakistan secured the release of Caitlan Coleman of Stewartstown, Pennsylvania, and her husband, Joshua Boyle, who were abducted five years ago while travelling in Afghanistan and had been held by the Haqqani network.

Coleman was pregnant when she was captured. The couple had three children while in captivity, and all have been freed, US officials said.

The Pakistani military confirmed the release and said the family was "being repatriated to the country of their origin."

But as of Thursday morning, the family's precise whereabouts were unclear, and it was not immediately known when they would return to North America.

The family was not in US custody, though they were together in a safe, undisclosed, location in Pakistan, a US national security official told the Associated Press news agency.

US officials had planned on moving the family out of Pakistan on a US transport plane, but at the last minute Boyle would not get on, the official said.

The couple have told US officials that they wanted to fly commercially to Canada, according to the official.

US officials describe the Haqqani network as a "terrorist organisation" and have targeted its leaders with drone attacks.

But it also operates like a criminal network. Unlike the Islamic State of Iraq and the Levant (ISIL) group, it does not typically execute Western hostages, preferring to ransom them for cash.

The US has long criticised Pakistan for failing to aggressively pursue the Haqqani network.

In a statement on Thursday, US President Donald Trump described the release as "a positive moment for our country's relationship with Pakistan".

US-Pakistan meeting

The release came as Lisa Curtis, a member of the National Security Council, was in the Pakistan capital, Islamabad, for talks with Pakistani officials on the implementation of the administration's new Afghanistan and South Asia strategy.

"Noting that US had a long track record of cooperation with Pakistan, the US delegation emphasised the importance of reinvigorating the bilateral relationship in order to achieve the common objectives of peace and stability in Afghanistan and the region," the Pakistan government said after Thursday's meeting.

The Pakistani army said its forces recovered the hostages after acting on US intelligence about their passage into Pakistan from Afghanistan.

However, one US official told Reuters news agency there was no indication that the hostages had been in Afghanistan in the days before they were freed.

The US believed the hostages were probably held by the Haqqani group in or near its headquarters in northwest Pakistan the entire time, two other US officials said.

John Kelly, Trump's chief of staff, said: "They’ve been essentially living in a hole for five years. That's the kind of people we're dealing with over there."

The release came together rapidly on Wednesday. It happened nearly five years to the day since Coleman and Boyle lost touch with their families while travelling in a mountainous region near the Afghan capital, Kabul.

The couple set off in summer 2012 for a journey that took them to Russia, the Central Asian countries of Kazakhstan, Tajikistan and Kyrgyzstan, and then to Afghanistan.

Coleman's parents last heard from their son-in-law on October 8, 2012, from an internet cafe in what Boyle described as an "unsafe" part of Afghanistan.

In 2013, the couple appeared in two videos asking the US government to free them from the Taliban.

Trump's message

In recent remarks on his Afghanistan policy, Trump took note of the billions paid to Pakistan "at the same time they are housing the very terrorists that we are fighting. But that will have to change, and that will change immediately".

However, in his statement on Thursday, he said: "The Pakistani government's cooperation is a sign that it is honouring America's wish that it do more to provide security in the region".

Trump said the release suggests other "countries are starting to respect the United States of America once again".

For her part, Chrystia Freeland, Canada's foreign minister, said in a statement her country was "greatly relieved" the family was safe, and she thanked the US, Afghan and Pakistani governments for their efforts.

"Joshua, Caitlan, their children and the Boyle and Coleman families have endured a horrible ordeal over the past five years. We stand ready to support them as they begin their healing journey," she said.

With additional reporting by Al Jazeera's Asad Hashim. Follow him on Twitter @AsadHashim