Now, groups like the brutal Islamic State and the Shabab in East Africa are magnets for several thousand readily duped Westerners, including scores of Americans. Many of them feel isolated from family and community, and long for something to believe in. They’re typically young men like the Minneapolis Somalis. “ISIS tries to instill that there is something greater that you can be doing,” Mr. Warsame said in an interview last year with the CBS show “60 Minutes,” after his arrest and before a federal judge sentenced him to 30 months in prison. “It kind of takes control of you,” he said.

Social media and online videos are powerful recruiting tools that the Islamic State has exploited skillfully and aimed at young people like him and his friends. “If they’re living in a context where they feel alienated, they feel like they’re not getting a fair deal, they can be open to indoctrination,” Charles B. Strozier told Retro Report. Mr. Strozier, a psychoanalyst who is the founding director of the Center on Terrorism at John Jay College of Criminal Justice in New York, added, “They’re susceptible to thinking of these larger messages which come flooding at them through the internet.”

They are not necessarily beyond salvation, though. Almost as if “Ticket to Heaven” were a training film, the federal court in Minneapolis has turned to a version of deprogramming as a possible solution. Only the word used in connection with jihadists is deradicalization. The court invited in Daniel Koehler, founder of the German Institute on Radicalization and Deradicalization Studies in Berlin. Mr. Koehler has concluded that extremists of all stripes share a sense that what is wrong with the world and what is wrong in their own lives are intertwined.

Many high school or college students feel woebegone: Parents are annoying or teachers are oppressive. Most young people figure out that there are various ways to cope. But for someone who has been radicalized — say, a teenager led to believe that his religion is being persecuted — the perspective can narrow and obvious solutions fade (except maybe violence). Mr. Koehler calls it “depluralization.” What he attempts, he told Retro Report, is to “repluralize the worldview, make it broader again, make them understand that there are no easy answers for single problems.”

That means, in part, reintegrating them back into the larger society and inculcating skills other than how to fire an AK-47 or strap on a suicide vest. He thinks that progress has been made with some of the young Somali men, but not all. The judge in Mr. Warsame’s case, Michael J. Davis, said he remained unpersuaded that the defendant had abandoned jihadist aspirations.

While the Islamic State in recent months has lost much of its territory in Syria and Iraq to United States-backed coalition forces, experts say it is not defeated. Thousands of militants remain in those two countries and presumably are still able to tempt gullible Western recruits, who are within reach via laptops and smartphones. And there’s always a chance that new death-hugging cults will arise. If the past is a guide, some young people are bound to be seduced into picking up a gun, convinced it’s their ticket to heaven.