U.S. and Pakistani officials said Thursday that they had rescued an American woman, her Canadian husband and their three young children from captivity by a militant network linked to the Taliban.

Pakistani officials said their army and intelligence agencies conducted the rescue operation based on intelligence provided by American authorities, delivering a boost to flagging relations between the United States and Pakistan.

Officials identified the rescued couple as Caitlan Coleman of Stewartstown, Pa., and Joshua Boyle of Canada. They disappeared five years ago while traveling in a mountainous area near Kabul, Afghanistan, during a backpacking trip through Central Asia.

Coleman was pregnant at the time. The couple had three children while in captivity.

“All hostages were recovered safe and sound and are being repatriated to their country of origin,” the Pakistani army said in a statement.

President Trump, who has sharply criticized Pakistan for failing to crack down on militants, offered praise for the country’s role.

“They worked hard on this and I believe they’re starting to respect the United States again,” Trump said at a White House event on healthcare, adding, “We hope to see this cooperation and teamwork” again in securing other hostages and counter-terrorism operations.

U.S. intelligence agencies had been tracking the whereabouts of the hostages and informed Pakistan that they had been brought into the country from Afghanistan via a border crossing in the Kurram tribal area on Wednesday, Pakistani officials said.

The rescue took place Wednesday night. According to Pakistani security sources, who spoke on condition of anonymity to discuss details of the operation, rescuers located a vehicle carrying the family southwest of the town of Kohat in Khyber Pakhtunkhwa province.

The security forces exchanged gunfire with the captors, capturing one while two others escaped, officials said.

Residents in Kohat said drones had been hovering over the town for the last 10 days, a possible sign of the involvement of U.S. intelligence agencies.

The operation “underscores the importance of timely intelligence sharing and Pakistan’s continued commitment” to fighting terrorism, the Pakistani army statement said.

The Haqqani network is a militant group aligned with the Taliban that has battled the U.S. military in Afghanistan for years and frequently targets Westerners. The group held U.S. Sgt. Bowe Bergdahl captive for five years before he was released in 2014 as part of a prisoner swap that saw five Taliban detainees released from the U.S. military prison at Guantanamo Bay, Cuba.

Coleman, Boyle and their children appeared in hostage videos several times, most recently in December, when Coleman pleaded with President Obama and incoming President Trump to free them from “the Kafkaesque nightmare in which we find ourselves.”

The Canadian government said it had been “actively engaged” with the U.S., Pakistan and Afghanistan on the case and expressed relief that the family had been freed.

“Joshua, Caitlan, their children and the Boyle and Coleman families have endured a horrible ordeal over the past five years,” Canadian Foreign Minister Chrystia Freeland said. “We stand ready to support them as they begin their healing journey.”

CAPTION

Democrat Doug Jones won Alabama’s U.S. Senate seat Tuesday. A cooking fire at a homeless encampment caused the Skirball fire, officials said. San Francisco Mayor Ed Lee, 65, died Tuesday. House Democrats called for an investigation into allegations of sexual misconduct by President Trump.

Democrat Doug Jones won Alabama’s U.S. Senate seat Tuesday. A cooking fire at a homeless encampment caused the Skirball fire, officials said. San Francisco Mayor Ed Lee, 65, died Tuesday. House Democrats called for an investigation into allegations of sexual misconduct by President Trump.

CAPTION

Democrat Doug Jones won Alabama’s U.S. Senate seat Tuesday. A cooking fire at a homeless encampment caused the Skirball fire, officials said. San Francisco Mayor Ed Lee, 65, died Tuesday. House Democrats called for an investigation into allegations of sexual misconduct by President Trump.

Democrat Doug Jones won Alabama’s U.S. Senate seat Tuesday. A cooking fire at a homeless encampment caused the Skirball fire, officials said. San Francisco Mayor Ed Lee, 65, died Tuesday. House Democrats called for an investigation into allegations of sexual misconduct by President Trump.

CAPTION

Democrat Doug Jones, whose uphill bid for U.S. Senate gathered strength when Republican Roy Moore was hit with charges of sexual misconduct with teenage girls, won Alabama’s special election Tuesday.

Democrat Doug Jones, whose uphill bid for U.S. Senate gathered strength when Republican Roy Moore was hit with charges of sexual misconduct with teenage girls, won Alabama’s special election Tuesday.

CAPTION

New York City's bomb attack suspect was allegedly inspired by Islamic State's call for attacks. The Thomas fire has grown to at least 230,000 acres. "The Shape of Water" and "Big Little Lies" led the Golden Globe nominations anounced Monday. Mario Batali stepped away from "The Chew" and his day-to-day business operations.

New York City's bomb attack suspect was allegedly inspired by Islamic State's call for attacks. The Thomas fire has grown to at least 230,000 acres. "The Shape of Water" and "Big Little Lies" led the Golden Globe nominations anounced Monday. Mario Batali stepped away from "The Chew" and his day-to-day business operations.

CAPTION

Santa Barbara County is under siege from the Thomas fire. From the GOP's perspective, Alabama's Senate race will yield one of two unhappy results. The Weingart Center wants to reshape skid row's skyline. If lawmakers can agree on a tax bill, will you owe more or less?

Santa Barbara County is under siege from the Thomas fire. From the GOP's perspective, Alabama's Senate race will yield one of two unhappy results. The Weingart Center wants to reshape skid row's skyline. If lawmakers can agree on a tax bill, will you owe more or less?

CAPTION

An explosive device exploded near Times Square during the morning rush hour Monday, injuring four people and snarling Manhattan transit, authorities said. Mayor Bill de Blasio described it as a terrorist act.

An explosive device exploded near Times Square during the morning rush hour Monday, injuring four people and snarling Manhattan transit, authorities said. Mayor Bill de Blasio described it as a terrorist act.

Special correspondent Ali reported from Peshawar and Times staff writer Bengali from Mumbai, India. Times staff writer Noah Bierman in Washington and special correspondent Aoun Sahi in Islamabad, Pakistan, contributed to this report.