On the night of March 10, 2004, as Attorney General John D. Ashcroft lay ill in an intensive-care unit, his deputy, James B. Comey, received an urgent call.

White House Counsel Alberto R. Gonzales and President Bush's chief of staff, Andrew H. Card Jr., were on their way to the hospital to persuade Ashcroft to reauthorize Bush's domestic surveillance program, which the Justice Department had just determined was illegal.

In vivid testimony to the Senate Judiciary Committee yesterday, Comey said he alerted FBI Director Robert S. Mueller III and raced, sirens blaring, to join Ashcroft in his hospital room, arriving minutes before Gonzales and Card. Ashcroft, summoning the strength to lift his head and speak, refused to sign the papers they had brought. Gonzales and Card, who had never acknowledged Comey's presence in the room, turned and left.

The sickbed visit was the start of a dramatic showdown between the White House and the Justice Department in early 2004 that, according to Comey, was resolved only when Bush overruled Gonzales and Card. But that was not before Ashcroft, Comey, Mueller and their aides prepared a mass resignation, Comey said. The domestic spying by the National Security Agency continued for several weeks without Justice approval, he said.

"I was angry," Comey testified. "I thought I just witnessed an effort to take advantage of a very sick man, who did not have the powers of the attorney general because they had been transferred to me."

The broad outlines of the hospital-room conflict have been reported previously, but without Comey's gripping detail of efforts by Card, who has left the White House, and Gonzales, now the attorney general. His account appears to present yet another challenge to the embattled Gonzales, who has strongly defended the surveillance program's legality and is embroiled in a battle with Congress over the dismissals of nine U.S. attorneys last year.

It also marks the first public acknowledgment that the Justice Department found the original surveillance program illegal, more than two years after it began.

Gonzales, who has rejected lawmakers' call for his resignation, continued yesterday to play down his own role in the dismissals. He identified his deputy, Paul J. McNulty, who announced his resignation Monday, as the aide most responsible for the firings.

"You have to remember, at the end of the day, the recommendations reflected the views of the deputy attorney general," Gonzales said at the National Press Club. "The deputy attorney general would know best about the qualifications and the experiences of the United States attorneys community, and he signed off on the names," he added.

Those comments appear to differ, at least in emphasis, from earlier remarks by Gonzales, who has previously laid much of the responsibility for the dismissals on his ex-chief of staff, D. Kyle Sampson. They stand in contrast to testimony and statements from McNulty, who has acknowledged signing off on the firings but has told Congress he was surprised when he heard about the effort.

The Justice Department and White House declined to comment in detail on Comey's testimony, citing internal discussions of classified activities.

The warrantless eavesdropping program was approved by Bush after the Sept. 11, 2001, attacks. It allowed the NSA to monitor e-mails and telephone calls between the United States and overseas if one party was believed linked to terrorist groups. The program was revealed in late 2005; Gonzales announced in January that it had been replaced with an effort that would be supervised by a secret intelligence court.