“We are not yet a country that detains people for their internet searches or deleted documents,” Ms. Stelzig said.

Prosecutors say that for at least two years, Lieutenant Hasson visited white supremacist and neo-Nazi websites, and studied the 1,500-page manifesto written by Anders Behring Breivik, a far-right Norwegian extremist who killed 77 people in 2011. They said that he also took the synthetic opioid Tramadol while at work and that he had obtained the drug illegally.

The Coast Guard declined to comment on the case on Thursday, citing the continuing investigation.

In writings discovered on his computer, prosecutors said, Lieutenant Hasson said he was a longtime neo-Nazi, but one who preferred “focused violence” to marches and rallies. A letter he drafted to friends in 2017, prosecutors said, contained musings about how to cause the maximum disruption to society.

But in public, Lieutenant Hasson gave little indication of his troubled thoughts.

Records indicate that he graduated from Greenway High School in Phoenix in 1987 and served in the Marines from 1988 until 1994 as a mechanic servicing F-18 jets. In 1993, he married Shannon Coleman in Hampton, Va.

After the Marines, he served in the Army National Guard for two years, according to court filings, and at some point after that joined the Coast Guard, and became an officer even though he did not attend college. With 28 years of military service, he would be nearing the Coast Guard’s mandatory retirement limit of 30 years.

Like many military families, the Hassons moved frequently, living in Arizona, Nevada, California, Virginia, North Carolina and New Jersey, according to property records. Along the way, he apparently had children — his lawyer referred to him in court as a father — but neither they nor his wife was present at the hearing on Thursday.