Updated

Veteran FBI agent Robert Hanssen will avoid the death penalty by pleading guilty to charges that he spied for Russia, his attorney said Tuesday.

"This is an appropriate resolution which we believe is beneficial to the government and to Mr. Hanssen and his family," defense attorney Preston Burton said.

Hanssen, only the third FBI agent to be accused of espionage, intends to plead guilty this week.

Hanssen pleaded not guilty May 31 to charges of spying for Moscow, and plans were set for an Oct. 29 trial. The federal indictment, issued May 16, accuses Hanssen of 21 counts of espionage.

Hanssen could have faced the death penalty because the government said his spying led to the death of two double agents.

The government alleged that Hanssen passed U.S. secrets to Moscow for 15 years in exchange for $1.4 million in cash and diamonds.

The FBI said it obtained original Russian documents that detailed Hanssen's alleged activities, including letters he allegedly wrote to his Russian handlers and secret codes he allegedly used to signal when and where he would drop documents.

Hanssen has been detained at an undisclosed location since he was arrested Feb. 18 at a Virginia park as he allegedly delivered a package for pickup by his Russian handlers.

Hanssen's attorneys had been negotiating for weeks on a deal that would allow him to reveal the secrets he sold to Moscow in exchange for the Justice Department agreeing to a life term. The deal will also allow Hanssen's wife, Bonnie, and his six children to receive benefits under his government pension, an official said on condition of anonymity.

Going to trial would have raised the prospect of prosecutors having to reveal in open court sensitive information about U.S. counterintelligence activities. For instance, Hanssen allegedly disclosed how the United States was intercepting Soviet satellite transmissions and the means by which the United States would retaliate against a nuclear attack.

A plea hearing was set for 9 a.m. Friday in U.S. District Court in Alexandria, Va., before Judge Claude Hilton.

The Associated Press contributed to this report.