An American woman, her Canadian husband and their three young children are now free after being held hostage for five years.
Pakistan secured the release of Caitlan Coleman and her husband, Joshua Boyle, after they were abducted and held by the Haqqani network, a group linked to the Taliban, US officials say.
Mr Boyle and Ms Coleman married in 2011 after meeting online, local media reported.
Mr Boyle was once married to Zaynab Khadr, the older sister of former Guantanamo Bay detainee Omar Khadr and the daughter of a late senior Al Qaeda financier.
Her father, Ahmed Said Khadr, and the family stayed with Osama bin Laden briefly when Omar Khadr was a boy.
The Canadian-born Omar Khadr was 15 when he was captured by US troops following a firefight at a suspected Al Qaeda compound.
He was taken to Guantanamo and ultimately charged with war crimes by a military commission.
He pleaded guilty in 2010 to charges that included murder and was sentenced to eight years plus the time he had already spent in custody.
Several years ago, Zaynab Khadr and her mother also upset many Canadians by expressing pro Al Qaeda views.
But officials had discounted any link between that background and Mr Boyle's capture, with one official describing it in 2014 as a "horrible coincidence".
Their six-month backpacking trip included a visit to Russia, the central Asian countries of Kazakhstan, Tajikistan and Kyrgyzstan.
The Washington Post reported that Ms Coleman had promised her family in September that she would not go to Afghanistan, even though Mr Boyle was fascinated by the country.
It is still unclear exactly when the couple were captured, but Mr Coleman's parents said they last heard from their son-in-law on October 8, 2012.
They said Mr Boyle contacted them from an internet cafe in what was described as an "unsafe" part of Afghanistan.
Soon after it is believed the couple were captured from the Wardak province, south-west of Kabul.
Unlike the Islamic State group, the Haqqani network does not typically execute Western hostages, preferring to ransom them for cash.
The Haqqani network had previously demanded the release of Anas Haqqani, a son of the founder of the group, in exchange for turning over the American-Canadian family.
In one of the videos released by their captors, Mr Boyle implored the Afghan Government not to execute Taliban prisoners or he and his wife would be killed.
Over the years, the captors had released a number of short videos and letters showing the family was still alive.
The first videos were sent to Ms Coleman's family in 2013 and were made public in 2014.
A letter was also sent to the Colemans in November 2015, in which their daughter wrote that she had given birth to a second child in captivity.
Mr Boyle's parent's said last December that a video had given them their first glimpse of their grandchildren.
"It is an indescribable emotional sense one has watching a grandson making faces at the camera, while hearing our son's leg chains clanging up and down on the floor as he tries to settle his son," the Boyles said in a written statement.
"It is unbelievable that they have had to shield their sons from their horrible reality for four years."
On Thursday, the couple also recorded a video, in which they recounted their first conversation with their son in five years.
"We got to hear his voice. It was amazing. He told us how much his children were looking forward meeting their grandparents," his mother, Linda Boyle, said.
The Toronto Star reported that Mr Boyle spoke to his parents after his release and told them he had been in the boot of the kidnappers' car with his wife and children when Pakistani forces rescued them.
He told the paper there had been a shoot-out and that the last words he heard from the kidnappers were, "kill the hostages".
"We know there was a shootout and Pakistan commandos carried out an attack and rescued the hostages," the high commissioner for Pakistan, Tariq Azim Khan, confirmed.
The Pakistani military said the family had been freed after they had crossed the border from Afghanistan and were "being repatriated to the country of their origin".
Three intelligence officials said the confrontation happened near a road crossing in the Nawa Kili area of the district of Kohat in north-west Pakistan.
In his statement on Thursday, President Donald Trump said the United States Government, working in conjunction with the Government of Pakistan, secured the release of the Boyle-Coleman family from captivity in Pakistan.
"This is a positive moment for our country's relationship with Pakistan," he said.
"The Pakistani Government's cooperation is a sign that it is honouring America's wishes for it to do more to provide security in the region.
"We hope to see this type of cooperation and teamwork in helping secure the release of remaining hostages and in our future joint counterterrorism operations."
The family's current whereabouts is unclear and it is not immediately known when they will return to North America.
US officials had planned on moving the family out of Pakistan on a US transport plane, said a US national security official who was not authorised to discuss the case publicly and spoke on condition of anonymity.
The family is not in US custody, though they were together in a safe, undisclosed location in Pakistan, the official said.