NORFOLK, Virginia — A naval flight officer who pleaded guilty last month to violating the federal Espionage Act will serve six years in confinement.

Lt. Cmdr. Edward C. Lin, 40, also will be dismissed from the Navy under the sentence issued late Friday by military judge Cmdr. Robert Monahan, who deliberated for four hours. Monahan sentenced Lin to nine years, but under a pretrial agreement he will serve six, receive credit for the more than 600 days he was held before trial and have three years suspended.

Lin's sentencing followed a two-day hearing during which he offered the first personal details in a case that once was reported as a sex-for-secrets intrigue.

Lin described a series of reckless, arrogant missteps in which he failed to report foreign contacts and that led him to share unspecified classified information.

"I'm physically ill when I think about what could have happened because of what I said," Lin said Friday.

Lin was arrested in September 2015 in Hawaii where he was planning to board a plane to China to meet a woman he met online. He initially faced espionage charges under the Uniform Code of Military Justice. But in May he pleaded guilty to two less onerous charges -- under the Espionage Act -- that he deliberately disclosed classified information. He also pleaded guilty to charges involving failure to report his foreign contacts, twice mishandling classified information and twice making false statements about his travel plans. Prosecutors dropped other charges, including adultery and prostitution.

When arrested, Lin had been assigned to the secretive Hawaii-based Special Projects Patrol Squadron 2. In court, he described in an emotional statement his parents sending him as a teenager out of his native Taiwan to avoid conscripted military service in a force that was looked down upon. When Lin joined the U.S. Navy in 1999, his father refused to talk with him for three years.

Federal agents began investigating Lin in January 2014 after receiving a tip concerning trips and communications with foreign contacts, testified Chris Mitchum, a special agent with the Naval Criminal Investigative Service. The NCIS and FBI began searching Lin's work and personal emails, finding he failed to report ties to two Taiwanese naval officers, a lobbyist and relationships with Chinese women, including one he met in a Honolulu massage parlor and the one he was traveling to meet when he was arrested.

But Lin's most serious missteps dealt with his mishandling of classified information and his sharing of it with two women. One was a U.S. citizen who worked in Washington as a lobbyist for a Taiwanese political party, and the other was an undercover FBI agent he knew as "Katherine Wu." Lin admitted he shared classified information with the lobbyist, writing in one email dated July 22, 2013, "This is something you'd probably never see in published literature but it's pretty close to ground truth," prosecutor Capt. Michael Luken said Friday.

Lin, who served on the Norfolk-based aircraft carrier USS Dwight D. Eisenhower in 2009 and 2010, said he also shared classified information with "Wu," who he believed was a Taiwanese immigrant, in August and September 2015 to impress her and let her know that U.S. military service was honorable.

Larry Youngner, Lin's civilian attorney, blamed an emotional attachment: Lin was was going through a divorce and believed "Wu" was a teacher also weathering a rocky marriage. She said her mother had died of cancer. Lin's mother, a teacher, died of cancer.

"His intention is to help someone like him, someone like his mother," Youngner said.

Lin faced as much as 36 years. Luken asked for 12 years, saying Lin still had knowledge of current classified information and a demonstrated "inclination to talk."