WASHINGTON — The director of the National Security Agency told Congress on Wednesday that “dozens” of terrorism threats had been halted by the agency’s huge database of the logs of nearly every domestic phone call made by Americans, while a senator briefed on the program disclosed that the telephone records are destroyed after five years.

The director, Gen. Keith B. Alexander, who heads both the N.S.A. and United States Cyber Command, which runs the military’s offensive and defensive use of cyberweapons, told skeptical members of the Senate Appropriations Committee that his agency was doing exactly what Congress authorized after the attacks of Sept. 11, 2001.

General Alexander said he welcomed debate over the legal justification for the program because “what we’re doing to protect American citizens here is the right thing.” He said the agency “takes great pride in protecting this nation and our civil liberties and privacy” under the oversight of Congress and the courts.

“We aren’t trying to hide it,” he said. “We’re trying to protect America. So we need your help in doing that. This isn’t something that’s just N.S.A. or the administration doing it on its own. This is what our nation expects our government to do for us.”