WASHINGTON — David H. Petraeus, the former director of the Central Intelligence Agency, told lawmakers on Friday that classified intelligence reports revealed that the deadly assault on the American diplomatic mission in Libya was a terrorist attack, but that the administration refrained from saying it suspected that the perpetrators of the attack were Al Qaeda affiliates and sympathizers to avoid tipping off the groups.

Mr. Petraeus, who resigned last week after admitting to an extramarital affair, said the names of groups suspected in the attack — including Al Qaeda’s franchise in North Africa and a local Libyan group, Ansar al-Shariah — were removed from the public explanation of the attack immediately after the assault to avoiding alerting the militants that American intelligence and law enforcement agencies were tracking them, lawmakers said.

In his first public appearance since he resigned last week, Mr. Petraeus testified before the House and Senate Intelligence Committees in back-to-back closed-door hearings as lawmakers from both parties continued to wrestle with questions about the Obama administration’s handling of the Sept. 11 attacks in Benghazi that killed Ambassador J. Christopher Stevens and three other Americans and why its public portrayal conflicted with the intelligence agencies’ classified assessments.

“They knew right away that there were terrorists involved in the operation,” said Representative C. A. Dutch Ruppersberger of Maryland, the top Democrat on the House Intelligence Committee.