COPENHAGEN — Arrested for stabbing a 19-year-old passenger on a commuter train in November 2013, Omar Abdel Hamid El-Hussein blamed the effects of hashish for his brutal, random and nearly fatal attack, telling a court last December that he had been gripped by wild fear and thought his victim wanted to hurt him.

Last weekend, just two weeks after his release from prison for the knife attack, Mr. Hussein went on another violent rampage, killing two strangers and wounding five police officers. But this time he was gripped not by drugs, but by a fanatical strand of Islam whose mission, according to a message he posted on Facebook shortly before the attacks, “is to destroy you.”

Mr. Hussein’s journey from drug-addled street thug to self-proclaimed jihadist declaring loyalty to the Islamic State has stirred soul-searching in liberal-minded Denmark over whether Islam, in fact, was really a prime motivator for his violence, or merely served as a justifying cover for violent criminality.

“This is a very difficult question to answer,” said Manu Sareen, the minister for integration and social affairs, who shortly before the attacks began a program to combat radicalization through outreach to parents, schools and other efforts.