Canadian Joshua Boyle and his US wife Caitlan Coleman were kidnapped while backpacking in Afghanistan in 2012. They had three children while in captivity.
They were rescued after a US tip-off during an operation near the Afghan border, the Pakistani army said.
US President Donald Trump said it was a "positive moment" for US-Pakistan ties.
"Ms Coleman gave birth to the couple's three children while they were in captivity," Mr Trump said in a White House statement. "Today, they are free."
He added: "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.
The Pakistani army said US intelligence agencies had been tracking the family in Afghanistan, and reported that on 11 October they had moved across the border into the Kurram tribal district of Pakistan.
In a statement it said: "The success underscores the importance of timely intelligence sharing and Pakistan's continued commitment towards fighting this menace through co-operation between two forces against a common enemy."
Videos of the couple have been released by the Taliban-aligned Haqqani network during their captivity. The insurgent group has been demanding the release of three of its prisoners in Afghanistan.
The latest video, released last December, showed the couple with two young boys. In it, Ms Coleman - who was pregnant when she and Mr Boyle were abducted - begged for an end to what she called their "Kafkaesque nightmare".
The US has accused Pakistan of not doing enough to counter Islamist militants who operate across its porous border with Afghanistan, and relations between Washington and Islamabad had recently been at a low ebb.