In a secret chat in November, according to court filings, two associates of a violent white supremacist group discussed whether drug use was in line with their political beliefs.

“Psychedelic Nazis . . . There’s nothing more Aryan than entheogenic drug use,” Andrew Thomasberg, 21, texted a friend, according to prosecutors, referencing plants that have psychedelic effects. But, he added, “Drug addiction is untermensch” — a Nazi term for people considered subhuman.

His friend replied: “That’s debatable. But I still have a bunch of shrooms anyway.”

Thomasberg was arrested at his home in McLean on Thursday, according to court filings, accused of possessing guns as a drug user and illegally buying an AK-47 in 2017 for that friend, who is cooperating with authorities. In federal court in Alexandria on Friday, FBI Special Agent Shawn Matthews, who testified that his focus is domestic terrorism, said Thomasberg took part in the deadly Unite the Right rally in Charlottesville in 2017 with a neo-Nazi group called Vanguard America. After Charlottesville, Matthews said, Thomasberg gravitated to another neo-Nazi group called the Atomwaffen Division that is “distinct in that it advocates for violence or violent acts to start a racial war in the United States.”

Prosecutors produced records of group chats in which Thomasberg said he was probably under investigation because he is “on record at shooting at people.” Thomasberg said he had shouted the n-word at a group of African Americans at a mall, according to the chat logs, talked about a coming “racial holy war” and described racially motivated mass shooters as “saints.”

Matthews said law enforcement found 20 guns in the home Thomasberg shared with his mother, stepfather and sister. Six were in Thomasberg’s bedroom; most were loaded. There was also a pistol in his car.

Marijuana was found in his home, although Thomasberg’s family said it belonged to his stepfather.

One person close to Thomasberg told the FBI last year that he had three or four firearms and regularly carried a handgun. He bought two rifles, a pistol and a handgun in the past four years, according to court records.

The case is one of several brought recently in federal court charging people linked to far-right groups with gun or drug crimes. A D.C. man who glorified violence against minorities on social media was sentenced last week to 10 months’ time served on a gun charge.

Judge Theresa Buchanan declined to grant bail for Thomasberg, calling the evidence “extremely concerning.”

Thomasberg’s mother, who declined to give her name, said there were “a lot of discrepancies” and “lies” in the case against her son. She said he is active in the Greek Orthodox Church.

“The United States seeking out a rich, white kid — not cool,” she said.

An attorney for Thomasberg, Elita Amato, declined to comment. In court, she emphasized that there was no evidence that Thomasberg was using drugs while buying guns.

A 2013 conviction was referenced in court by the judge; Thomasberg would have been a juvenile at the time, and those records are not accessible.

In June, he texted the friend who is now cooperating, known in court papers as B.B., that he was “carrying enough gear and supplies to set the new high score and wouldn’t want to have to explain that to a cop.”

According to Matthews in his affidavit, “high score” is a reference to mass shootings.

Thomasberg bought the AK-47 for B.B. in October 2017 at the Sterling, Va., gun store where he worked, in violation of store policy, according to Matthews. The gun was found when police searched B.B.’s home this year as part of a separate investigation. Matthews said Thomasberg described the gun in an interview Thursday as a “straw purchase.” B.B. said the pair made up a bill of sale for the gun as a “joke” with the price $14.14; the number 14 is a reference to a white-supremacist slogan.

Along with LSD and mushrooms, according to prosecutors, Thomasberg and B.B. discussed using marijuana, opium and the prescription stimulant Modafinil.

In July, Thomasberg applied for a concealed-carry permit in Fairfax and was denied.

Eric Clingan, a defense attorney, said he considered calling Thomasberg as a witness during the murder trial of a man who was eventually convicted of shooting and killing another man at a Fairfax County shopping center last year. Clingan said his client, Manvinder Aulakh, was friends with Thomasberg and had learned self-defense techniques from him.

But Clingan said he dropped those plans after a background check revealed that Thomasberg had talked about marching in Charlottesville with white-supremacist groups.

“My client and I determined that we didn’t want Mr. Thomasberg to testify in any manner,” Clingan said.

Justin Jouvenal contributed to this report.