Nicholas Young, 36, of Fairfax, Va., was arrested Aug. 3 at Metro Transit Police headquarters in Washington. He was charged with attempting to provide material support to the Islamic State. Here's what you need to know. (Monica Akhtar/The Washington Post)

For seven years, while Nicholas Young patrolled the Washington area’s Metro system as a transit police officer, other law enforcement agents were watching him.

In those years, authorities say, he threatened FBI agents, gave advice to suspected terrorists and mused about joining the Islamic State. But it was not until last week that federal agents concluded that Young, 36, of Fairfax, Va., had committed the crime of attempting to support a terrorist organization. He was arrested at Metro Transit Police headquarters Wednesday and terminated; he appeared in court still wearing part of his patrol uniform. The arrest marks the first time a U.S. law enforcement officer has been accused of trying to aid a terrorist group.

Young, a convert to Islam, sent codes for mobile messaging cards to an undercover federal agent in the belief that they would be used by Islamic State fighters overseas to communicate, according to a criminal complaint filed in federal court in Alexandria.

He came under surveillance because Metro Transit Police had alerted the FBI to unspecified “concerns,” Chief Ron Pavlik said.

According to authorities, Young has been with the transit police since 2003.

“Obviously, the allegations in this case are profoundly disturbing. They’re disturbing to me, and they’re disturbing to everyone who wears the uniform,” Metro General Manager Paul J. Wiede­feld said in a statement.

Since coming under scrutiny, Young was in touch with FBI agents, an undercover agent and a person working secretly for the agency. His first public conversation with the FBI was in September 2010. From January 2011 to February 2012, he was in touch with an undercover agent.

The investigation appeared to stall for more than a year. Then, in 2014, Young began communicating with a person working for the FBI who pretended to be a disillusioned U.S. military reservist of Middle Eastern descent. That person spoke with Young regularly until October 2014, when he pretended to join the Islamic State abroad. The account he had set up to speak with Young was then taken over by undercover agents.

Authorities said that in the years they watched and interacted with Young, there never was any credible or specific threat to the Metro system. The court papers detail vague threats over the years to kill FBI agents or bring guns into federal court. Young allegedly threatened to kidnap and torture an agent who interviewed him and to leave the head of anyone who betrayed him in a cinder block at the bottom of Virginia’s Lake Braddock.

But according to the criminal complaint, Young was focused on activity abroad, not in the D.C. area, and the FBI did not take his threats against agents seriously. He told law enforcement at one point that he had traveled to Libya twice in 2011 to fight against Moammar Gaddafi. And he allegedly gave a person working with law enforcement advice on how to travel to Syria — including how to avoid undercover agents. Believing the person had actually made it abroad, authorities said, Young then complied with a request to purchase gift cards for mobile messaging accounts used in Islamic State recruiting. The codes, worth $245 according to authorities, were redeemed by the FBI, not by ISIS.

In a message to that person he allegedly praised the 2015 Charlie Hebdo attack in France, writing, “Hopefully now people understand there are some lines you don’t cross . . . this gave the West a taste of what Muslims face every day.”

Dina Ahmad, who has lived in the neighborhood for 13 years, speaks to members of the media as police search the home of Metro Transit Police officer Nicholas Young. "Something was off about him," says Ahmad. "it's crazy he's a police officer." (Nikki Kahn/The Washington Post)

In a brief court appearance, Young wore a plain white T-shirt and the black uniform pants of a Metro police officer. He did not yet have a defense attorney.

At various points, according to the criminal complaint, Young told agents that he tortured animals as a child, had dressed up as Jihadi John at a 2014 Halloween party and also has dressed up as a Nazi and collected Nazi memorabilia. For the Jihadi John costume, according to the complaint, Young “stuffed an orange jumpsuit with paper to portray a headless hostage, and he carried that around with him throughout the party.”

He described that costume when police came to his house in June in response to an allegation of domestic violence, according to the criminal complaint.

Authorities on Wednesday had police tape around Young’s suburban Virginia townhouse.

Dina Ahmad has lived in Young’s neighborhood for 13 years. Like many other residents, she often saw Young in his front yard working on his truck. She said that Young appeared to keep to himself but that something seemed “off about him” as well.

“I would never just look at somebody and say, ‘Hey, they’re a terrorist,’ but I can believe it,” she said. “He was just weird. There was something off about him. You could tell.”

She was more surprised — and concerned — to learn that he was a police officer.

“That makes it even worse,” she said.

Young appears to own a large number of firearms. A Metro police officer told authorities that during an off-duty weapons training event in March 2015, Young brought an Egyptian AK-47, a Kimber 1911 .45-caliber pistol and an AK-47 AMD rifle. The training officer told the FBI that Young also owned a semi­automatic AK-47 RPK, an 8mm Mauser rifle and a World War II-era Russian Nagant rifle, according to the court papers.

During the years he was surveilled and contacted by both FBI agents and undercover operatives, Young expressed concern about such tactics. He told associates that he had several “burner phones,” according to a court affidavit, and regularly took the battery out of his cellphone to avoid detection. He warned associates to avoid social media and communication by email. When trying to move money out of the country last year, Young allegedly said, “Unfortunately I have enough flags on my name that I can’t even buy a plane ticket without little alerts ending up in someone’s hands.”

Young is the seventh person this year to be charged in a terrorism-related case in Northern Virginia. Like the others, he is accused of having contact with other radicals without being part of an organized group, as Islamic State encourages lone-wolf attacks in the United States.

In all but one, the plans were encouraged by operatives working for FBI.

“This case reflects the challenges that law enforcement is facing from the dangerous spread of violent radicalization that threatens our communities at home and abroad,” an FBI spokesman said.

Adam Goldman, LaVendrick Smith, Faiz Siddiqui, Lori Aratani, Dana Hedgpeth and Jennifer Jenkins contributed to this report.