US officials confirmed that American Caitlan Coleman, her Canadian husband Joshua Boyle and their three children have all been safely recovered.
The family was freed after a tip-off from US intelligence agencies that they had been moved into Pakistan from Afghanistan on Wednesday.
The couple were kidnapped whilst backpacking in Afghanistan in 2012.
They have been held since then by the Haqqani network, which has links to the Taliban.
Ms Coleman was pregnant when they were kidnapped and they have had three children while in captivity.
The rescue operation took place in the Kirram tribal district along the Afghan border, according to the Pakistan army.
They confirmed that a family of five had been rescued by Pakistani troops from “terrorist custody”.
The family’s rescue was hailed as a “positive moment for our country’s relationship with Pakistan” by the White House.
In a statement President Donald Trump said: “The Pakistani government’s co-operation 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 co-operation and teamwork in helping secure the release of remaining hostages and in our future joint counter-terrorism operations.”
Pakistan’s army said the success of the mission showed “the importance of timely intelligence sharing”.
They said it also demonstrated “Pakistan’s continued commitment towards fighting this menace through co-operation between two forces against a common enemy”.
Pakistan said the family was in the process of being repatriated, but their current location is unclear.
The family were last seen in December 2016 when they appeared in a video appealing to their governments to negotiate their release.