A former contractor for the National Security Agency pleaded guilty Thursday to stealing secret documents over two decades and keeping them at his Maryland home.

Harold T. Martin, 54, admitted to one felony count of willful retention of national defense information in Baltimore federal court. Prosecutors said that Martin is expected to be sentenced to nine years in prison with three years of supervised release on July 17 as part of a plea deal. Another 19 counts Martin faced are expected to be dismissed at sentencing.

Martin was arrested by heavily armed FBI agents at his Glen Burnie, Md. home in August 2016. He initially pleaded not guilty to 20 counts of willfully retaining classified information and was due to go to trial in June, but prosecutors announced this week that he would be arraigned again, signaling a change in plea.

Prosecutors accused Martin of a "breathtaking" theft of government secrets between 1996 and 2016, possibly the largest in American history. Federal agents seized dozens of laptops and digital devices from Martin's home, as well as six bankers boxes full documents. At least 50 terabytes of data were also recovered.

Martin's defense team said their client, a former Navy lieutenant who held various security clearances, had no intention to harm his country or the intelligence agencies he served. One of his lawyers previously described him as a "compulsive hoarder" who took work documents home with him.

During his court appearance Thursday, Martin told a federal judge that he was diagnosed with ADHD and took medication for that disorder.

"Today's plea is an affirmation of what Mr. Martin and his defense team have maintained from the beginning of this case. His actions were the product of mental illness. Not treason," his lawyers said in a statement.

Authorities said the felony count Martin pleaded guilty to involved a top-secret NSA leadership briefing from March 2014 that he had multiple copies of.

The NSA has suffered a series of significant breaches in recent years. Most notably, Edward Snowden disclosed a cache of classified material in 2013, exposing U.S. government surveillance programs. Martin, like Snowden, had worked as a contractor for Booz Allen Hamilton.

People have stolen government secrets throughout history but intelligence contractors hoarding reams of classified information at their homes appears to be something new.

CLICK HERE TO GET THE FOX NEWS APP

Last year, another Maryland man who had worked at NSA pleaded guilty to keeping numerous top-secret U.S. defense materials at home. At his sentencing, Nghia Hoang Pho, 67, told a federal judge he took copies of U.S. government documents and writings containing national defense information so he could work from home and possibly earn a promotion. He got 5 ½ years in prison.

It's not clear whether the NSA has instituted new protections in the wake of Martin's case.

Fox News' William Mears and The Associated Press contributed to this report.