Casey Spain had been out of prison on sexual assault charges for only 20 days when he was arrested for possessing a firearm.

He was set up by FBI agents who had been monitoring him for years, after tips from both prisoners and prison officials about his interest in Islamist terrorism.

Now, the 29-year-old from Richmond will go to federal prison for an additional 10 years. He was sentenced Monday in Richmond federal court after pleading guilty to a weapons charge.

The case is similar to that of Yusuf Wehelie, a Burke, Va., 26-year-old who was sent to prison for 10 years on firearms charges after talking about committing a terrorist attack.

Wehelie, however, was paid to move several guns; he had not been trying to buy one himself.

Casey Spain, 29, of Richmond with a tattoo of an Islamic State flag he had etched on his back while in prison. (N/A/ U.S. Attorney's Office for the Eastern District of Virginia)

While in prison, Spain became radicalized and spoke of his plans to commit violence, according to court documents. Spain asked a family member to send him copies of al-Qaeda’s Inspire magazine, the documents state, and told two prisoners he had sworn an oath of loyalty to the Islamic State.

Spain, who had “Cop Killa” tattooed on his face before he went to prison in 2010, had a tattoo of the Islamic State flag put on his back while behind bars, officials said.

In a recorded call to an inmate after his release, he said he put a photo of the tattoo on Facebook and that extremists overseas told him “it was a nice image,” even though tattoos are “haram,” forbidden in Islam.

Spain said he was banned from Facebook because of that photograph.

One prisoner said that in late 2016, Spain said that when he was released, he would commit a suicide attack on a police station or Marine base. During his brief weeks of freedom in August 2017, he was recorded saying his probation officer couldn’t stop him from joining the Islamic State abroad and was tracked talking with apparent ISIS supporters on Facebook.

Spain converted to Islam at age 15, according to his lawyers. He was in a Virginia juvenile jail at the time, they said, and needed protection.

“He is not mature. He was locked up when he was 15. He still acts like he is 15. He can’t do simple basic life skills, like banking, and he can’t drive,” his sister said in court filings.

Spain was abandoned by his mother and beaten and burned by one of his three stepmothers, his attorney said. He got little attention or even food as a child.

Defense attorney Paul Gill argued in court filings that Spain was radicalized in jail and prison, and that “putting Mr. Spain back into those breeding grounds for a long time is counterproductive.”

He said there was no evidence that Spain was planning to act on his violent words and, to the contrary, appeared to be interested in finding work and paying child support.

Prosecutors countered that Spain’s inability to obey the law inside or outside prison, as well as his violent history, make him a serious threat.

In 2006, Spain was convicted of statutory burglary, possession of a sawed-off shotgun and malicious wounding. The last charge came after he stabbed someone with a sword while trying to force his way into a party. In 2008, he was caught trying to elude police.

His most serious offense came in 2010, when he entered a friend’s home, then abducted the other boy’s 15-year-old sister and tried to rape her.

Spain also faces 41 years in state prison for violating the release terms of his two previous convictions.

“While the government acknowledges that the defendant may have endured difficult periods in his life during his unfortunate childhood . . . he squandered opportunities to better himself and, instead, sought out opportunities to repeatedly return to a life of increasingly violent crime,” prosecutors Raj Parekh and Brian Hood wrote in a sentencing memorandum. “For every month the defendant is incarcerated, the public will be given that much more protection from future crimes by him.”