WASHINGTON -- U.S. investigators took months to piece together evidence that led to the conclusion that drone strikes had killed two Western hostages and two Americans who worked for al-Qaida, U.S. officials said Friday.

New details were emerging about how the U.S. learned -- and announced this week -- the pair of deadly drone strikes had killed hostages Warren Weinstein and Italian Giovanni Lo Porto and the two al-Qaida operatives.

The drone strike was ordered because officials believed there were four members of al-Qaida's leadership in the building in the tribal areas of northern Pakistan. But they later learned six bodies had been buried instead of the four they expected, two U.S. officials said, speaking on condition of anonymity because they weren't authorized to discuss the matter publicly.

The drone strike was carried out by the CIA, which runs a covert drone operation. The two American al-Qaida leaders were Ahmed Farouq, a dual U.S.-Pakistani national who was an al-Qaida operations leader in Pakistan, and Adam Gadahn, an American who served as an al-Qaida spokesman, who was killed in a separate strike on a second compound.

Coincidental intelligence emerged that Weinstein, a contractor with the U.S. Agency for International Development who was captured in 2011, was dead, but intelligence officials didn't know how, when or where.

They began investigating, parsing through intercepts, and interviewing local sources in Pakistan, the officials said. It wasn't until two weeks ago that they got the crucial piece of intelligence that led them to conclude that Weinstein and Lo Porto were killed in the January strike.

The location of these hostages was a closely guarded secret even within al-Qaida. Because hostages are so valuable, the group takes extraordinary precautions not to talk about them electronically.

"It is a cruel and bitter truth that in the fog of war generally and our fight against terrorists specifically, mistakes, sometimes deadly mistakes, can occur," President Barack Obama said.

On Friday, the Pakistan Ministry of Foreign Affairs issued a statement of condolences to the hostages' families.

"Having lost thousands of innocent civilians in the war against terrorism, Pakistan can fully understand this tragic loss and stands with the families of Weinstein and Lo Porto in this difficult time," the ministry said. "The death of Mr. Weinstein and Mr. Lo Porto in a drone strike demonstrates the risk and unintended consequences of the use of this technology that Pakistan has been highlighting for a long time."

Meanwhile, in Italy, Foreign Minister Paolo Gentiloni is seeking to explain to Parliament why it took three months to learn about the death of Lo Porto in the U.S. drone strike. Gentiloni told lawmakers Friday that in an inaccessible war zone, where hostage-taking is frequent, it took that long for U.S. intelligence to verify Lo Porto had been killed.

Military technology may grow ever more sophisticated, but there still is no surefire way to ensure innocents will not be caught in harm's way, even by the most elite of U.S. forces.

In 2010, the U.S. Navy's SEAL Team 6 tried to rescue Scottish aid worker Linda Norgrove from Taliban captors in Afghanistan. She was killed by a grenade thrown by one of the American commandoes.

"Sometimes you get it wrong," said retired Army Col. Peter Mansoor, a professor of military history at Ohio State University. "There's no way to have a perfectly clean war."

In the case of the hostages killed when the CIA targeted an al-Qaida compound, Mansoor said, "It was simply incomplete information and you're never going to have complete information. ... There's no way to completely excise these sorts of collateral damage incidents from military affairs."

- News researcher Jennifer Farrar in New York contributed to this report.