American officials refused to identify the Americans or their jobs in Yemen, where the Pentagon and the C.I.A. have been training Yemeni security forces in addition to carrying out the drone strikes. But a senior American official said one individual involved in the shooting was a lieutenant colonel with the elite Joint Special Operations Command and the other was a C.I.A. officer.

It was unclear whether the two American officers violated embassy security protocols when they visited the barbershop, apparently alone. In high-risk countries like Yemen and Pakistan, American diplomatic personnel are often tightly restricted in where and when they can travel outside the embassy walls, and are typically accompanied by armed security personnel.

“Per standard procedure for any such incident involving embassy officers overseas, this matter is under review,” Ms. Harf said in the email.

The killings have an echo of a 2011 case in which a C.I.A. security officer, Raymond A. Davis, was jailed for weeks after killing two Pakistanis on a crowded street in Lahore. The ensuing furor brought relations between the C.I.A. and Pakistan’s spy service to perhaps their lowest ebb since the Sept. 11 attacks.

The Yemeni government is a staunch counterterrorism ally, and administration officials are no doubt seeking to avoid a replay of the 2011 debacle. “There will certainly be an investigation, and one would have to assume it will be informed by what happened in Pakistan,” one American official said.

American officials have voiced fears about the violence erupting in Yemen. The State Department announced on Wednesday that it had closed its embassy in Sana to the public because of security concerns, citing recent attacks against Western interests in Yemen as the reason for temporarily suspending operations.

The violence came close to the president’s doorstep on Friday when militants believed to be from Al Qaeda’s franchise attacked a security vehicle and killed three soldiers in the area of the presidential palace. News reports said the militants had fought a prolonged gunfight in the streets of the capital before escaping. In a second attack in the Bayda Province, militants believed linked to Al Qaeda killed two soldiers and injured many more in an ambush, according to officials in the area.