WASHINGTON — An American aid worker and another man held hostage by Al Qaeda were killed in an American drone strike in Pakistan in January, government officials disclosed on Thursday, underscoring the perils of a largely invisible, long-distance war waged through video screens, joysticks and sometimes incomplete intelligence.

Intending to wipe out a compound linked to the terrorist group, the Central Intelligence Agency authorized the attack with no idea that the hostages were being held there despite hundreds of hours of surveillance, the officials said. Even afterward, they said, the agency did not realize at first that it had killed an American it had long sought to rescue, with the wrenching news becoming clear over time.

The violent death of an American at the hands of his own government proved a searing moment in a drone war that has come to define the nation’s battle with Al Qaeda, especially since President Obama took office. Visibly upset, Mr. Obama came to the White House briefing room shortly after his staff issued a written statement announcing the deaths to make a rare personal apology.

“As president and as commander in chief, I take full responsibility for all our counterterrorism operations,” the grim-faced president told reporters as television cameras broadcast his words. “I profoundly regret what happened,” he added. “On behalf of the United States government, I offer our deepest apologies to the families.”

The government is conducting two reviews of the drone strike to determine what went wrong, and the episode could force a broader rethinking of Mr. Obama’s approach to fighting Al Qaeda. Under the president’s policy, drone strikes are to be authorized only when it can be concluded to a “near certainty” that there will not be civilian casualties.

Image Warren Weinstein, an American held hostage by Al Qaeda since 2011, was killed in an American counterterrorism operation. Credit... via Associated Press

The two hostages, Warren Weinstein, an American kidnapped in 2011, and Giovanni Lo Porto, an Italian seized in 2012, were killed Jan. 15 in a remote area in Pakistan known as a Qaeda sanctuary, officials said. An American affiliated with Al Qaeda, Ahmed Farouq, was killed in the same strike. Another American member of Al Qaeda, Adam Gadahn, was killed in a separate strike in the same region Jan. 19, according to the officials.

Just as the C.I.A. did not know the hostages were present, it also did not know that the American Qaeda members were at the strike targets and they had not been specifically targeted, officials said. Mr. Farouq was the deputy head of Al Qaeda’s relatively new branch in India and was not publicly identified as an American until Thursday. Mr. Gadahn was better known as a Qaeda spokesman.

Officials who spoke on condition of anonymity to discuss intelligence operations said it took weeks to piece together what happened.

Intelligence agencies picked up information soon after the January strikes that Mr. Weinstein was dead, but they were not immediately clear how. They pursued theories that he could have died in an American strike, during a Pakistani military operation or at the hands of his captors.

Only after pulling together disparate clues did they link the deaths of Mr. Weinstein and Mr. Lo Porto to the January drone strike, the officials said, and only last week did intelligence officials report to Mr. Obama that they had what they called the highest level of confidence. Mr. Obama ordered that the episode be declassified, but he said nothing to Prime Minister Matteo Renzi of Italy when he visited the White House last Friday.

Instead, after preparations had been made, Mr. Obama called Mr. Renzi on Wednesday to inform him what had happened and also called Mr. Weinstein’s wife, Elaine Weinstein. Aides described it as one of the most painful moments of his presidency. “It’s like your worst fears realized,” said one aide, who asked not to be named describing the president’s reaction. “He took it pretty hard.”

Image Giovanni Lo Porto, second from left, in a 2011 photograph, at work in Multan, Pakistan. He was killed in a drone attack in January. Credit... Andrea Parisi/Margherita Romanelli, via Associated Press

In a written statement, Ms. Weinstein said the family was “devastated” by the news and added that it looked forward to learning more about what happened.

But she said his captors bore responsibility. “The cowardly actions of those who took Warren captive and ultimately to the place and time of his death are not in keeping with Islam, and they will have to face their God to answer for their actions,” she said.

The issue of killing Americans through drone strikes has been an acutely delicate one for Mr. Obama, who two years ago announced in a speech at the National Defense University that he was beginning to scale back the aerial campaign and restrict it to cases of genuine threat to the United States and its people.

His administration has concluded that the federal government has the right to use deadly force against Americans tied to Al Qaeda if capture is not feasible. In the case of the two Qaeda figures killed in January, no legal determination would have been needed because it was not known that they were at the bombed sites.

Some members of Congress criticized the administration or called for more oversight. “Warren Weinstein did not have to die,” said Representative Duncan Hunter, Republican of California. “His death is further evidence of the failures in communication and coordination between government agencies tasked with recovering Americans in captivity — and the fact that he’s dead, as a result, is absolutely tragic.”

Human rights groups that have criticized the Obama administration’s aggressive use of drone strikes said the deaths of the hostages underscored the flaws in the policy. “Today’s demonstration of transparency is a welcome step, but apology and redress should be available for all civilians killed in U.S. drone strikes, not just Americans and Europeans,” said Naureen Shah, the director of Amnesty International USA’s program on security and human rights.

Image Adam Gadahn Credit... Agence France-Presse — Getty Images

Jameel Jaffer, deputy legal director of the American Civil Liberties Union, said the fact that the government did not know that the hostages or American Qaeda figures were present showed the problems in the drone war. “These and other recent strikes in which civilians were killed make clear that there is a significant gap between the relatively stringent standards the government says it’s using and the standards that are actually being used,” he said.

Josh Earnest, the White House press secretary, rejected the criticism, saying there was no evidence that the strikes deviated from normal practice, and he added that the families would receive financial compensation. Mr. Obama said a full review would identify any changes that should be made to avoid similar errors. “We will do our utmost to ensure it is not repeated,” Mr. Obama said.

Mr. Obama did not sign off on this specific strike, aides said, because he has authorized the C.I.A. and military to carry out drone attacks without further consultation if they fit certain criteria. Mr. Obama said the operation was conducted “fully consistent with the guidelines” for such missions. “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,” he said.

Even though Mr. Obama announced that the two counterterrorism operations had been declassified, there were limits to the White House’s transparency. Mr. Obama did not say that the C.I.A. had carried out the strikes, or even that they involved drones, nor did he say that they occurred in Pakistan.

Under the terms of a secret arrangement brokered in 2004, the C.I.A. was allowed to conduct lethal strikes inside the tribal areas of Pakistan, but neither the American nor the Pakistani government could acknowledge their existence. The pace of drone operations in Pakistan has declined sharply in recent years. But even as the American military withdraws from Afghanistan, the C.I.A. has pushed to keep certain bases in that country open so operatives can run missions across the border to gather intelligence for drone strikes.

Mr. Weinstein, 73, a resident of Rockville, Md., was a business development expert working on contract for the United States Agency for International Development when he was kidnapped in August 2011 in Lahore, Pakistan, just four days before he was scheduled to return to his family in the United States. Al Qaeda released videos of him, and news media reports from as recently as last week indicated that he was still assumed to be alive.