WASHINGTON — Pakistan abruptly freed the CIA contractor who shot and killed two men in a gunfight in Lahore after a deal was sealed Wednesday to pay $2.34 million in “blood money” to the men’s families. The agreement, nearly seven weeks after the shootings, ended a tense showdown with a vital U.S. ally that had threatened to disrupt the war on terrorism.

In what appeared to be a carefully choreographed conclusion to the diplomatic crisis, a U.S. official said Pakistan had paid the families whose pardoning of Raymond Davis set the stage for his release. That arrangement allowed Secretary of State Hillary Rodham Clinton to assert in a news conference the U.S. didn’t pay compensation.

But the U.S. government “expects to receive a bill at some point,” said the official, who spoke only on condition of anonymity because the situation was so sensitive. The payments to families in Pakistan are roughly 400 times as high as the U.S. has paid to families of many civilians wrongfully killed by U.S. soldiers in the wars in Iraq and Afghanistan.

Under negotiations to free Davis, the U.S. Embassy in Lahore said the Justice Department had opened an investigation into the Jan. 27 shootings. In a statement, the embassy thanked the families for their generosity in pardoning Davis but did not mention any money changing hands.

The deal to secure Davis’ release had been in the works for some time, with the most intense negotiations over the past three weeks, another U.S. official told The Associated Press.

The arrangement deliberately bypassed the question of whether Davis was immune from prosecution because of diplomatic status, the official said. That had been a central legal issue in the case, but by negotiating Davis’ release under Islamic sharia law the issue could be resolved outside the jurisdiction of the police and court system that arrested and held him on suspicion of murder.

Davis, 36, left the country immediately for Kabul in neighboring Afghanistan, where he was expected to be debriefed extensively about his time in custody, Pakistani and U.S. officials said.

In the U.S., an elated Rebecca Davis learned of her husband’s release in a phone call. She never blinked, she said, always believing her husband would be set free.

“I knew. I just didn’t know how long,” she said, speaking outside her home near Denver. “I just knew in my gut that he’d be home.”

The killings and then the detention of Davis triggered a fresh wave of anti-American sentiment in Pakistan and tested the sometimes shaky alliance that is seen as key to defeating al-Qaida and ending the war in Afghanistan.

“The East Bay Times is honored for its relentless efforts to obtain police body camera videos, inspection data, and other public records in the wake of the deadly Ghost Ship fire,” the Northern California Society of Professional Journalists announced Wednesday.