If he could not join the Islamic State overseas, Yusuf Wehelie once said, he would massacre military recruits in Springfield, Va. He especially wanted to kill Marines.

“Go to work, kill as much people as I can,” the Fairfax County man told an undercover FBI agent. “If I’m going to do that, I want to do a lot of damage, and I don’t want to get one guy. I want to get, like, 20 of them.”

That threat put Wehelie, a 26-year-old from Burke, Va., in prison for the next decade.

“I have grave concerns about a young man even talking about such a thing,” Judge Gerald Bruce Lee said Friday in Alexandria federal court before imposing the sentence. “I will take you at your word.”

It is a punishment far harsher than Wehelie’s actual crime — possession of firearms by a felon — would garner and the maximum allowed by law.

The case highlights a tension inherent in many counterterrorism operations. Law enforcement agents want to prevent an attack, even if they cannot prove it is coming. But critics say the result is often punishing words that do not rise to the legal bar for the crime of terrorism support.

Wehelie did not decide to get a gun on his own; he was paid $300 to deliver four weapons from one undercover FBI agent to another. It was, Lee acknowledged, “a crime of opportunity.”

Wehelie was arrested last June because FBI agents feared he would act on his disturbing words. Wehelie was flying to Minnesota, and Assistant U.S. Attorney John Gibbs said in court that there was concern he would sneak over the border to Canada and then fly to the Middle East. If he was stopped at the airport, Gibbs said in a court filing, Wehelie might have gone ahead with a domestic attack.

“The government had little choice but to arrest the defendant in the interest of public safety,” he wrote.

[Detained six years ago in Egypt and arrested now on a weapons charge]

A retired FBI counterterrorism agent said law enforcement sometimes has to take a person off the street on what seem like minor charges.

“Sometimes hands are forced . . . and investigators have to act before they want to,” Jeffrey Ringel said, speaking generally and not specifically about Wehelie’s case. “Suspects can go operational overnight, and we’ve seen that in New Jersey and California and other places. And then you’ve got another terrorist on your hands.”

Federal guidelines called for a sentence of about three years, and prosecutors initially asked for a punishment within those parameters. There was audible shock in the courtroom when Lee read his sentence and tears from Wehelie’s large family.

Amy Jeffress, a former national security prosecutor, said it is rare for judges to depart from sentencing guidelines, but that it does happen in cases such as this one where a charge unrelated to terrorism is used as a “last resort.”

“You can’t charge someone with a crime based on statements alone in most circumstances, but they can be considered at sentencing,” she said. “The judge has to decide whether it was just boasting or hyperbole, or whether it’s serious.”

Defense attorney Nina Ginsberg argued that there was overwhelming evidence that her client posed no real threat. Wehelie did nothing suspicious over a year of surveillance, she said. He declined a suggestion from the undercover agent to send blankets to Islamic State fighters overseas. He never made concrete plans to travel abroad or to commit a terrorist attack, she said, and when he had a chance to handle the automatic weapons he was paid to transport he showed no interest. He never asked about the plan for the guns, and he nearly missed the transfer because he was passed out on drugs.

A few weeks after making his disturbing comments, she said, he texted the undercover agent with reservations.

“I’m starting to have doubts about ISIS,” he told the operative. “They’ve been doing a lot of bad stuff, killing innocent people. . . . I don’t know what team to be on. . . . I just loved the fact that they were building an Islamic state.”

Wehelie then stopped responding to the undercover agent’s messages.

“He briefly flirted with some of the ideas that ISIS was putting out in the world,” which he found through extremist Instagram posts, Ginsberg said. But “as horrific as these statements were, what really matters is what someone did and didn’t do.”

She added that Wehelie was dealing with undiagnosed post-traumatic stress disorder from having been abused by Egyptian police on his return from a trip to Yemen in 2010. That incident became national news because his brother was stranded in Egypt for six weeks.

“From the time he returned from Egypt, he was seen by everyone who knew him as an entirely different person,” she said. He dropped out of college, could not hold a job, withdrew from his family and became emotionally volatile.

“This was a desperate young man who was falling apart,” Ginsberg said.

His previous felony conviction was for a 2011 burglary, in which Wehelie and a friend stole a laptop and several bottles of alcohol from someone’s home. He then earned another conviction for repeatedly smoking marijuana while on probation. His final offense was for embezzling money from a sports store where he worked.

Wehelie first met the undercover FBI agent during the investigation of a cigarette-trafficking operation.

Faiza Patel, co-director of the Brennan Center’s Liberty and National Security Program, said terrorism prosecutions in the United States often involve more talk than action.

“A lot of times it seems as if the FBI treats these kind of statements from Muslims as being far more dangerous than they do from other kinds of persons,” she said. “There’s a real question as to whether these individuals were ever going to do anything without the FBI leading them by the hand.”

In court Friday, Wehelie apologized and disavowed his violent words.

“It does not represent Islam. It does not represent my parents, who are the true representatives of Islam and the American Dream,” he said. The Somali immigrants “came here with nothing, and now they have everything,” he added.

When he leaves prison, Wehelie said he would like to help other people with PTSD.

“I’m going to be successful,” he said.