WASHINGTON, May 15 — President Bush intervened in March 2004 to avert a crisis over the National Security Agency’s domestic eavesdropping program after Attorney General John Ashcroft, Director Robert S. Mueller III of the F.B.I. and other senior Justice Department aides all threatened to resign, a former deputy attorney general testified Tuesday.

Mr. Bush quelled the revolt over the program’s legality by allowing it to continue without Justice Department approval, also directing department officials to take the necessary steps to bring it into compliance with the law, according to Congressional testimony by the former deputy attorney general, James B. Comey.

Although a conflict over the program had been disclosed in The New York Times, Mr. Comey provided a fuller account of the 48-hour drama, including, for the first time, Mr. Bush’s role, the threatened resignations and a race as Mr. Comey hurried to Mr. Ashcroft’s hospital sickbed to intercept White House officials, who were pushing for approval of the N.S.A. program.

Describing the events as “the most difficult of my professional career,” Mr. Comey appeared before the Senate Judiciary Committee as part of its inquiry into the dismissal of federal prosecutors and the role of Attorney General Alberto R. Gonzales. Several lawmakers wanted to examine Mr. Gonzales’s actions in the N.S.A. matter, when he was White House counsel, and cited them to buttress their case that he should resign.