The Federal Bureau of Investigation has charged a government contractor with stealing classified secrets, part of what officials said was a probe into how key U.S. computer-spying tools were removed from the National Security Agency.

Authorities unsealed court papers Wednesday charging Harold Thomas Martin, 51 years old, of Glen Burnie, Md., with theft of government property and unauthorized removal of classified materials. Mr. Martin, a former Navy officer, was arrested in late August, the papers said, but the charges were kept under seal while the FBI investigated.

It is the second black eye for the spy agency and one of its main contractors, Booz Allen Hamilton Holding Corp. , after Edward Snowden leaked stolen records in 2013. Mr. Martin’s arrest followed a probe launched in August after an entity calling itself Shadow Brokers claimed online to have a large cache of files that appeared to be NSA spying tools, and said it was looking to sell the information. Such programs are used to penetrate computer systems of foreign governments like Russia and China, according to officials familiar with the matter, and for that reason are among the NSA’s most closely held secrets.

Officials said they are still trying to determine Mr. Martin’s motives or intent for taking the information. “He appears to be a hoarder,” said one official, but investigators are still trying to determine what may have been his ultimate goal. Some of the material found at his residence included the same type of offensive cyberweapons also offered for sale by Shadow Brokers in August, officials said.

Mr. Martin, a former surface warfare officer who left the Navy in 2000, has been in custody and couldn’t be reached for comment. His lawyer, Jim Wyda, said the charges “are mere allegations.…There is no evidence that Hal Martin intended to betray his country. What we do know is that Hal Martin loves his family and his country.” He added that Mr. Martin “has devoted his entire career to protecting America.”