In an unusual moment on Wednesday night, Mr. Trump appeared to telegraph the family’s impending release.
“America is being respected again,” the president said during a speech on his tax plan in Harrisburg, Pa. “Something happened today where a country that totally disrespected us called with some very, very important news. And one of my generals came in, they said, you know, I have to tell you, a year ago they would have never done that. It was a great sign of respect. You’ll probably be hearing about it over the next few days.”
Mr. Trump did not mention Ms. Coleman, Mr. Boyle or Pakistan, but the revelation was notable for a president who had often complained that President Barack Obama shared what Mr. Trump viewed as important secrets, such as battle plans against the Islamic State.
Pakistan’s relationship with the United States has been rocky. The United States has long accused Pakistan’s military and its intelligence agency of harboring or ignoring militants, and relations have grown increasingly strained over Pakistan’s role in Afghanistan.
In a statement about the hostage release, the Pakistani army said: “The success underscores the importance of timely intelligence sharing and Pakistan’s continued commitment towards fighting this menace through cooperation between two forces against a common enemy.”
The end of the family’s captivity was a victory for the State Department officials and the F.B.I.-led Hostage Recovery Fusion Cell that had worked on the case for years. The group was created under the Obama administration to improve the government’s efforts to free hostages and to ensure their families received timely information about them.
Previously, the Haqqani network had demanded the release of Anas Haqqani, one of its commanders, in exchange for the family’s freedom. The Afghan government captured Mr. Haqqani in 2014, and he was sentenced to death. The militant group had threatened to kill the family if he was executed.
In December 2016, the militants released a video of the family, including footage depicting their children. Ms. Coleman described her time as a hostage as “Kafkaesque” and said she had been “defiled.”
“Indeed, they threaten to retaliate against our family,” she said. “Their group will do us harm and punish us. So we ask that you are merciful to their people and, God willing, they will release us.”
An earlier video made public in August 2016 showed the couple. During it, Ms. Coleman urged the American government to “help stop this depravity.” She also said her captors “will execute us.”
Earlier attempts to bring the family home fell short. In January 2016, Colin Rutherford, a Canadian, was freed after Qatar arranged a prisoner swap with the Afghan government. Officials had hoped Mr. Rutherford would be the first in a series of releases, including Ms. Coleman and her family.
But that never materialized, for reasons that remain unclear. The Obama administration sought to jump-start talks with the Taliban but those efforts faltered after the American military killed Mullah Akhtar Muhammad Mansour, the Taliban’s leader, in a drone strike in May of 2016.
The Haqqanis are believed to be holding an American university professor who was kidnapped in August of 2016. On a video released earlier this year, the man, Kevin King, pleaded for Mr. Trump to free him: “Have mercy on me and get me out.”
Another American, Paul Overby, disappeared in May 2014 and has not been seen since his abduction. He was trying to interview the head of the Haqqani network when he was abducted.
The Trump administration has had modest success in freeing Americans held overseas. In April, an Egyptian-American woman was released in Egypt after being held for nearly three years on human trafficking charges. Another American, Otto Warmbier, a student, was released from North Korea but died days later. His family said Mr. Warmbier, who had been in a coma, was tortured.
Three other Americans remain imprisoned in North Korea.
The C.I.A. director, Mike Pompeo, tried to open a backchannel to the Syrian government to help free Austin Tice, an American journalist and former Marine officer, who is being held in Syria. His exact whereabouts is unknown, but American officials believe the Syrian government knows where he is being held.