WASHINGTON — A former contractor for the National Security Agency, the federal government's super-secret codebreaker, pleaded guilty Thursday to charges that he stole and held onto classified government secrets.

Harold Martin of Glen Burnie, Maryland, entered a guilty plea in a Baltimore federal courtroom. When he was arrested in 2016, investigators said thousands of secret and top-secret documents in printed and digital form were found in his house and car.

After Thursday's hearing, his defense lawyers said Martin's actions "were the product of mental illness, not treason."

FBI investigators estimated at the time that Martin's stash included digital information equal to 500 million pages of text and images, easily the largest theft of official secrets ever, dwarfing what intelligence officials say was stolen by Edward Snowden — also an NSA contract employee.

But during the hearing, Martin pleaded guilty to one charge involving a single document, described as "a March 2014 NSA leadership briefing outlining the development and future plans for a specific NSA organization." Charges involving 19 other documents were dropped in exchange for the plea.

Prosecutors did not accuse Martin of revealing the information to foreign governments or any other person. A major puzzle from the beginning has been why Martin took the materials home and what he intended to do with them.

"It's time to close the lid on Pandora's Box," Martin told the judge in a brief statement.

Federal District Court Judge Richard Bennett set a sentencing date of July 17. Martin's lawyers agreed with prosecutors that federal guidelines call for a sentence of nine years. He will get credit for the two-and-a-half years he has been jailed pending trial.

The Justice Department also proposed that after serving his sentence, Martin should be forbidden to have contact with any foreign person.

"That's not to suggest that there was or would be any such contact," Bennett said.

Public defender James Wyda described Martin as "deeply remorseful" and "focused on taking care of his health and making amends as best he can."