NORFOLK, Va. -- When federal agents stopped Lt. Cmdr. Edward C. Lin in the Honolulu airport on Sept. 11, 2015, he was about to board a plane to China to meet a woman with whom he had been communicating online since April.

But Lin, 40, who held a top secret security clearance and was assigned to a secretive Hawaii-based patrol squadron at the time, had lied to the Navy about where he was going. Instead, he had told his command he planned to spend 10 days in Alexandria -- where he had previously lived while assigned as a staff aide to an assistant secretary of the Navy -- because telling his leadership he was going to Virginia rather than the communist adversary required a less rigorous approval process.

That wasn't the naval flight officer's first misstep, but it was one of many detailed Thursday during a daylong court-martial at Naval Station Norfolk as Lin -- who immigrated to the U.S. from Taiwan in 1994 and who joined the Navy in 1999 -- pleaded guilty to charges that cast him less like a government spy and more as an officer with a number of foreign friends whose career derailed under his own recklessness and arrogance.

The Navy's original charges against Lin, in April 2016, included counts of espionage, one of the most serious offenses under the Uniform Code of Military Justice and punishable in some cases by death. He also had faced charges including prostitution and adultery, which were dropped during preliminary hearings in 2016.

As part of Thursday's plea agreement, Lin pleaded guilty to two counts that he deliberately disclosed classified information to two women -- a violation under the federal Espionage Act -- instead of the military's version of the charge. He also pleaded guilty to charges that he violated general orders for failing to report foreign ties and the mishandling classified information in two incidents and with two counts of making false official statements.

A statement from Lin's attorney expressed the sailor's love for the United States. "His greatest personal triumph was becoming a US citizen and serving for over 17 years in the US Navy," the statement from Larry Youngner read in part.

A month before Lin was arrested in Hawaii he already had started to meet with one woman, an undercover FBI agent who went by "Katherine Wu." He believed that she, like him, was a Taiwanese immigrant, and that she worked as a contractor for that country's Ministry of Foreign Affairs translating articles.

Lin told military judge Cmdr. Robert Monahan he knew it was wrong to tell the woman classified information about the operations and capabilities of his command, Special Projects Patrol Squadron 2, but he did so because he wanted to convince her that U.S. military service is an honorable profession.

"Were you doing this to impress her?" Monahan asked Lin.

"Yes, sir," he answered.

Lin again told Monahan that he knew he was disclosing classified information when he responded to emails in April and May 2012 sent to him by a woman who worked as a lobbyist for a Taiwanese political party in Washington whom he had befriended and met for occasional lunches.

That woman was one of a handful of foreign ties that Lin told Monahan he failed to report to his commanders, including two Taiwanese military officials with whom he said he shared meals and naval information. Lin got in touch with one of those officials when he traveled to Taiwan in November 2013 to help arrange a meeting with Yeong-Kang "Richard" Chen, an admiral who was then the U.S. equivalent to the chief of naval operations.

Information about that meeting was not publicly discussed in Thursday's hearing but, Lin, who was working at the time in Washington as an aide to Vice Adm. Joseph Mulloy, the deputy assistant secretary of the Navy for budget and the director of the fiscal management division, also admitted to lying about where he was traveling. That time, Lin also said he was staying in Alexandria to bypass scrutiny when instead he told Monahan he went to Taiwan to visit family.

By February 2014, Lin had moved to Hawaii. In February 2015, he was traveling through San Francisco International Airport when a Homeland Security agent found a flight manifest from a summer patrol mission in a flight suit he had packed into checked luggage.

Instead of properly dealing with the two-page document when that mission ended months earlier, Lin admitted he'd left it unsecured during the flight. Instead of calling his command for guidance once it was found, he said he instead told the agent to destroy it.

"When I handed over the manifest to the homeland security agent, I was more concerned over what that would do to my career than in safeguarding the nation's secrets," Lin said.

Lin, who was going through a divorce from his wife around this time, said he was also too ashamed to report two other relationships he forged while in Hawaii. It was there that he befriended a Chinese massage therapist living in the U.S. and also struck up an internet relationship with another Chinese citizen, the woman he was traveling to meet when apprehended.

"Divorce is shameful in my culture," Lin said, adding he was worked in a competitive job and worried that his command would look down upon him for socializing outside his marriage.

Lin faces up to 36 years of confinement. His sentencing is scheduled for June 1 and 2.