WASHINGTON — Five years after they were seized by a terrorist network in the mountains of Afghanistan, an American woman, her Canadian husband and their children — all three born in captivity — are free after a dramatic rescue orchestrated by the US and Pakistani governments, officials said Thursday.

The US said Pakistan accomplished the release of Caitlan Coleman of Stewartstown, Pennsylvania, and her husband, Canadian Joshua Boyle, who were abducted and held by the Haqqani network, which has ties to the Taliban.

The operation, which came after years of US pressure on Pakistan for assistance, unfolded quickly and ended with what some described a dangerous raid, a shootout and a captor’s final, terrifying threat to “kill the hostage.” Boyle suffered only a shrapnel wound, his family said.

US officials did not confirm the details.

“Today they are free,” President Donald Trump said in a statement, crediting the US-Pakistani partnership for securing the release. Trump later praised Pakistan for its willingness to “do more to provide security in the region” and said the release suggests other “countries are starting to respect the United States of America once again.”

The couple were kidnapped in October of 2012 while on a backpacking trip that took them to Russia, the countries of Kazakhstan, Tajikistan and Kyrgyzstan, and then to Afghanistan. Coleman was several months pregnant at the time, “naive,” but also “adventuresome” with a humanitarian bent, her father James told The Associated Press in 2012.

The Pakistani military said early Thursday the family was “being repatriated to the country of their origin.” But as of Thursday evening, it was not known when they would return to North America. They were together in a safe, undisclosed location in Pakistan, according to a US national security official, who wasn’t authorized to discuss the case publicly and spoke on condition of anonymity.

The Pakistani military said the family had been freed in “an intelligence-based operation by Pakistan troops” after they’d crossed the border from Afghanistan.

Boyle and the High Commissioner for Pakistan to Canada described a scene in which gunshots rang out as Boyle, his wife and their children were intercepted by Pakistani forces while being transported in the trunk of their captors’ car.

Boyle told his parents there was a shootout in which some of his captors were killed and said the last words he’d heard from the kidnappers were, “kill the hostage,” his father, Patrick told reporters after speaking with his son. The younger Boyle also told his father he’d been hit by shrapnel in the leg.

Three intelligence officials said the confrontation happened near a road crossing in the Nawa Kili area of the district of Kohat in northwest Pakistan.

The high commissioner, Tariq Azim Khan, said, “We know there was a shootout and Pakistan commandos carried out an attack and rescued the hostages.”

A US military official said a military hostage team had flown to Pakistan Wednesday, prepared to fly the family out. The team did a preliminary health assessment and had a transport plane ready to go. But sometime after daybreak there, as the family members were walking to the plane, Boyle said he did not want to board.