Former FBI counterintelligence agent Robert P. Hanssen pleaded guilty yesterday to 15 counts of spying for Moscow, bringing to a close what a prosecutor called one of the most "disturbing and appalling" espionage cases in American history.

Hanssen, 57, will receive a life sentence under a plea bargain that calls for him to first spend six months debriefing his former colleagues about the treachery that netted him $1.43 million in cash, diamonds and foreign bank deposits. The deal, which was struck secretly on June 14, allows him to avoid the death penalty.

The 10-minute hearing in U.S. District Court in Alexandria revealed new details about the 25-year FBI veteran's two-decade-long second career as a mole. The FBI has developed a detailed chronology of his activities from 1985 to 1991 and from 1999 until his Feb. 18 arrest.

Yesterday, Hanssen attorney Plato Cacheris filled in the gaps. He said Hanssen had actually begun spying in 1979 and stopped voluntarily in 1981. Sources said Hanssen passed information to the Soviets multiple times in that period, mostly through "dead drops" in New York, but stopped after his wife, Bonnie, caught him with documents and confronted him.

Cacheris said his client resumed spying from 1985 to 1991 but did not pass secret information to the Russians between 1992 and 1999. Sources said Hanssen wrote at least one rambling and bizarre letter to Moscow in that second period of dormancy.

At yesterday's hearing, Hanssen looked much more animated than he did at his May 31 arraignment. Although he has lost 40 pounds since his arrest, the father of six smiled and shook hands with his attorneys. His brief answers to U.S. District Judge Claude M. Hilton's questions were clear and forceful, although he twisted his fingers together behind his back as he spoke.

After telling the judge he was "very satisfied" with his attorneys, Hanssen, still wearing his prison jumpsuit, pleaded guilty to attempted espionage, 13 specific acts of spying and conspiring to commit espionage.

Government officials have been eager to learn exactly when Hanssen was actively spying and how he evaded capture for so long. The plea, which prosecutors agreed to after Hanssen answered investigators' questions for 10 hours, clears the way for a full reconstruction.

"This is one of those rare cases where both sides have won," Cacheris said in court. Hanssen "very much wanted to make amends. That's a big reason for this disposition. He wanted to tell his former agency what he had done and how he had done it."

But U.S. Attorney Kenneth Melson said: "Mr. Hanssen is not a winner. . . . He disgraced himself, and he disgraced his badge. . . . His plea of guilty today brings to a close one of the most disturbing and appalling stories of a turncoat imaginable."

Hanssen's betrayals add up to the worst act of U.S. espionage since the case of CIA officer Aldrich H. Ames, who was sentenced to life in prison in 1994.

Cacheris, who also represented Ames, and federal officials said the two men caused similar damage to American security, though Hanssen passed more documents. Officials say Hanssen betrayed nine double agents, including two who were later executed, and provided details about U.S. nuclear war preparations, several top-secret communications programs and a listening tunnel beneath the Soviet Embassy in Washington.

Over the years, Hanssen left more than two dozen packages in dead drop sites in New York and a series of Washington area parks. In all, he turned over more than 6,000 pages of classified documents without ever meeting with a Russian handler.

As part of the deal, prosecutors dropped six counts of espionage.

In addition, under a 1996 law designed to encourage spies' families to cooperate, Bonnie Hanssen will receive spousal benefits from his FBI pension. Bonnie Hanssen is eligible for 55 percent of Hanssen's pension, or about $40,000 a year, because she has "fully cooperated" and "did not have criminal culpability," said Assistant U.S. Attorney Randy I. Bellows, the lead prosecutor on the case.

Bonnie Hanssen already is receiving some money from the government, but the pension benefits will start officially when Attorney General John D. Ashcroft approves them about the time Hanssen is sentenced Jan. 11, Bellows said. Hilton already has agreed to impose a life sentence as long as prosecutors are satisfied that the former spy has fully cooperated.

Hanssen agreed to forfeit the $1.4 million he received from the Russians. But the government has not been able to track down and seize any specific assets except two Rolex watches and $50,000 the Russians left for Hanssen at the time of his arrest. Bonnie Hanssen will keep the family's three cars and their home in Vienna, which is heavily mortgaged.

Under the agreement, Hanssen is barred from profiting from his exploits. If he participates in a book or movie, his share will go to the government, and he may not talk to the media until after his sentencing. Bonnie Hanssen is not bound by those provisions.

Hanssen decided to plead guilty after learning that the best result he could hope for with a trial was a life sentence, Cacheris said.

The central problem for the defense was that Hanssen was caught on videotape leaving a garbage bag full of classified documents for the Russians right before his arrest. That attempted espionage count alone would have carried more than 30 years in prison.

After consulting with two psychiatrists, defense attorneys told Hanssen that his mental health issues would not meet the legal standard for an insanity defense and could backfire by making a jury more inclined toward the death penalty. One of those doctors, Alen Salerian, has said publicly that Hanssen has "emotional wounds," and sources say the agent was obsessed with pornography.

A former stripper, Priscilla Sue Galey, has said Hanssen gave her nearly $100,000 in fine jewelry, a used Mercedes-Benz, a trip to Hong Kong and cash.

Cacheris said his client had a feeling the jig was up, even before he was caught. "When he went on Feb. 18 to that last drop site, he felt he was going to be arrested, and he went anyway," Cacheris said.

"Something has aroused the sleeping tiger," Hanssen wrote to the Russians.

Hanssen's wife and children, who have avoided the media spotlight, did not attend yesterday's hearing. But the defense has asked that he be sent to the federal prison at Allenwood, Pa., so that the family can continue to visit him.

"He was a great dad," Jane Trimber, one of Hanssen's daughters, said in an interview.

The Justice Department spent several months debating whether to work out a deal with Hanssen. The new nominee for FBI director, Robert S. Mueller III, argued that Hanssen should pay for his crimes with his life, but CIA Director George J. Tenet and other intelligence officials argued that the government needed to know what Hanssen had given away.

"The decision to forgo the death penalty in this case was a difficult one," said Deputy Attorney General Larry Thompson. "We determined that the interests of the United States would be best served by a course that would enable the government to fully assess the magnitude and scope of Hanssen's espionage activities, an objective that could not be achieved if we had sought the death penalty."