ALBUQUERQUE — Wen Ho Lee walked out of court a free man Wednesday after a federal judge repeatedly apologized for incarcerating him for nine months without trial and angrily rebuked the Clinton administration for its handling of a case that "embarrassed this entire nation."

In a morning marked by high drama, laughter and tears of joy, the former Los Alamos nuclear weapon scientist agreed in thickly accented English to a negotiated deal that brings an abrupt end to the highly controversial case.

Lee pleaded guilty to one felony charge of illegally retaining national defense information. He was sentenced to the 278 days he has served since his arrest. The government dismissed all 58 other counts, many of which carried life sentences.

"Next few days, I'm going fishing," Lee declared with a broad grin on the mobbed courthouse steps after his release. His lawyer Mark Holscher called it "a sweet day indeed."

In a sworn statement provided as part of the deal, Lee said for the first time that he did not intend to harm the United States when he downloaded classified nuclear weapon data onto an unsecured computer and portable tapes at Los Alamos and that he had not passed the tapes or their contents to anyone.

Lee, 60, also agreed to submit to intense debriefings by government investigators for 10 days over the next three weeks and further questioning if necessary over the next year to satisfy government concerns about why Lee created the tapes and what he did with them. Lee could face further prosecution if he fails to comply.

Norman Bay, U.S. attorney for New Mexico, called the resolution of the high-profile and highly controversial national security case "a favorable disposition for the government and a fair disposition for the defendant."

But the court hearing was dominated by U.S. District Judge James A. Parker's stunning summation, an emotion-charged monologue in which he repeatedly apologized to Lee and bitterly condemned government prosecutorial tactics.

Speaking in somber tones to a packed and hushed courtroom, Parker excoriated what he called the "top decision-makers in the executive branch." He particularly criticized the White House, U.S. Atty. Gen. Janet Reno, Energy Secretary Bill Richardson and the FBI for their roles in bringing the case.

"They have embarrassed this entire nation and each of us who is a citizen of it," Parker said.

The decision to prosecute Lee, he said, "was made at the highest levels of the executive branch in Washington, D.C." He cited a meeting of senior Justice and Energy Department officials at the White House on Dec. 4, six days before Lee was indicted.

The executive branch, Parker warned, "has enormous power, the abuse of which can be devastating to our citizens."

In contrast, Parker effusively praised Lee's lawyers as "outstanding" and said that they would have provided a "formidable" defense had the case gone to trial.

"You turned a battleship in this case," the judge told Lee's lawyers from the bench.

Prosecutors sat stone-faced through much of Parker's harsh scolding. The FBI's chief investigator, Robert Messemer, whose recantation last month of his own testimony sharply undermined the prosecution's case, scowled. Messemer, a beefy man with slicked-back hair, avoided reporters after the hearing.

An FBI source in Washington said that, while Messemer's conduct in the case will be routinely reviewed, the agency seems to believe that his testimony "wasn't that inaccurate" and it is doubtful he will be disciplined.

But Parker, who took over as chief federal judge in New Mexico this month, repeatedly said that the government "misled" him by exaggerating evidence against Lee in December when prosecutors insisted that the Taiwan-born scientist should be denied bail and held incommunicado in jail until his trial.

"Dr. Lee, I feel great sadness that I was led astray" during the December bail hearing, Parker said.

Parker, 63, also criticized John J. Kelly, the former U.S. attorney here, who quit in January to run for Congress. Before leaving, Kelly "personally argued vehemently against your release and persuaded me not to release you," the judge told Lee.

"In hindsight, you should not have been held in custody," he added.

Until recently, Lee spent his time in virtual solitary confinement in a Santa Fe jail. He was allowed to see his family one hour a week and to exercise alone one hour a day. He was shackled hand and foot even during those periods, however, as well as during his meetings with his lawyers.

Parker complained that the government moved much too slowly, despite his urgings, to ease the conditions of Lee's confinement.

"Dr. Lee, you were terribly wronged by being held in pretrial custody in demeaning and unnecessarily punitive conditions," Parker said. "I am truly sorry."