NAVAL STATION NORFOLK, Va. — A Navy officer accused of espionage has pleaded guilty to less serious charges as part of a negotiated plea deal.

Lt. Cmdr. Edward Lin, 40, admitted to the charges during a court-martial before a military judge on Thursday.

Last year the military had accused Lin of two instances of espionage, three instances of attempted espionage and several instances of mishandling classified information and failing to report contact with foreign agents.

The new deal allows Lin to plead not guilty to military espionage charges but guilty to charges that include failing to report foreign contacts, mishandling classified information and disclosing secret information to a female friend working for a Taiwanese political party in Washington, D.C. and an undercover FBI agent posing as an employee of Taiwan’s ministry of foreign affairs.

Lin was arrested on Sept. 11, 2015 at the Honolulu International Airport on his way to Shanghai, China to visit a Chinese national he met online – a female prison guard.

The arrest also followed several meetings with an undercover FBI agent who operated under the alias, “Katherine Wu.” Over a series of meetings from August to September in 2015, Lin told the agent general details of his secretive unit — Special Projects Patrol Squadron Two ‘Wizards’ (VPU-2). The Wizards, based at Marine Corps Air Station Kaneohe, Hawaii, use specialized signals intelligence aircraft to collect data on potential U.S. adversaries as part of one of the most secretive units in the service.

In addition to passing information classified as secret to the FBI agent, Lin also offered his opinion on international developments in the Western Pacific to the employee of the Taiwanese political party over a period of about two years starting in 2012.

During the trial, Lin admitted to using secret information he gained during a 2009 exercise when he was assigned to PACOM to tell the employee of the political party how the U.S. believed, “a certain entity would act in a certain way.”

Lin admitted he had agreed not to acknowledge, confirm or deny the information related to his work at VPU-2 and the operational details learned during the 2009 exercise.

Following Lin’s arrest, NCIS and federal investigators interrogated Lin and combed through his possessions and his electronic correspondence.

Based on the evidence, the government also charged Lin with not reporting foreign contacts he had with naval attaches at the Taipei Economic and Cultural Representative Office – Taiwan’s embassy equivalent in Washington – an American employee of a Taiwanese political party and female Chinese national massage therapist to whom Lin loaned money.

He also pleaded guilty to two instances of mishandling classified material. In 2014, Lin had accidentally left two flight manifests in his flight suit from a deployment that included search and rescue code names. When filled out, the documents were classified secret. During a customs search at the San Francisco airport, a Homeland Security officer discovered the manifests and Lin asked the officer to destroy the documents in violation of procedure.

Federal investigators also found study notes for unit training Lin made from memory in his apartment that the government determined were secret and improperly stored.

To round out the charges, Lin also admitted to giving an incorrect U.S. address on a leave request on two separate foreign trips – one to Taiwan in which he met the head of the Taiwanese Navy and the planned trip to Shanghai where he was to meet the Chinese prison guard.

The charges to which Lin has plead guilty are serious and carry a maximum penalty of more than 30 years, forfeiture of pay and dismissal from the service. However, the actions outlined in the Thursday military trial are less severe compared to the espionage charges that would have put Lin behind bars for life if he was convicted.

Lin knew some of the Navy’s most sensitive secrets from his time not only at VPU-2 but also as a congressional liaison where he would have been privy to the Navy’s black program portfolio, several sources have confirmed to USNI News. If he was inclined, his knowledge could be extremely useful to potential U.S. adversaries, the sources said.

But the evidence presented at daylong trial didn’t uncover a master spy but a middle aged naval officer in the midst of a divorce who used some of his lower level knowledge to impress women.

“It sounds like they thought they had Al Capone but they got the gang that couldn’t shoot straight,” Rob “Butch” Bracknell, a former Marine and military lawyer, told USNI News on Thursday.

Now that he’s admitted guilt to the charges, Lin will face a sentencing hearing in early June. U.S. Fleet Forces commander Adm. Phil Davidson will assign the final punishment based on guidance from the military judge.

Lin has been held in pre-trial confinement of the service since his arrest on Sept. 11, 2015.

Originally from Taiwan, Lin joined the Navy as an enlisted sailor in 1999, a year after becoming a U.S. citizen.