Marwan al-Dwiri wasn’t your usual terrorism suspect. At 22, the young Tunisian was a promising rapper who had nothing to do with violent radical Islam; he wasn’t even very religious. He was beginning to make headlines with his music, rhyming in Arabic about freedom of expression and police brutality. He may have been political, but he was no Islamist. Yet today he goes by the jihadist name Abu Ameen al-Tunisi, and has traded the trappings of hip-hop culture for the Islamic State group’s virulent strain of Sunni Islam. His social media presence shows him not with girls and fast cars, but in what may be Iraq as a fighter for ISIS. He turned into a radical jihadist, like many other young Muslim men in North Africa and Europe, after a stint in prison.

He had been jailed in 2012 under what his lawyer claimed were false charges of marijuana possession. Al-Dwiri, who rapped under the name Emino, said he believed the real reason he was arrested was for shedding light on Tunisia’s police brutality, unfair arrests and rampant political and economic corruption. His lyrics, and those of the rappers with whom he often worked, were critical of the police and the Tunisian state.

But while this may not have won him many friends in law enforcement, it was not a crime -- and after the imprisonment and criminal trial that followed, al-Dwiri came out of his brush with Tunisian repression a changed man. A secular government had managed to turn an opposer who wanted more freedom into someone who was after nothing less than the state’s destruction by an Islamic caliphate.

"I sold my soul and my body for ISIS, and I will come back to liberate my country of the garbage that is polluting it,” he wrote on Facebook, likely from Iraq, on the day of the Bardo Museum attack last month when gunmen aligned with the Islamic State killed 21 people.

The path leading him to Iraq and the Islamic State group began with his first arrest, according to friends and people in Tunisia’s hip-hop scene. He was arrested with eight other rappers on drug charges and sentenced to six months in prison, said Bijan Mashhadi, one of the rappers’ associates, who spoke to music website HipHop DX.

“In Tunisia, getting caught with marijuana has a minimum sentence of one year in prison,” Mashhadi said. “But this was intentional to make a point to all other rappers."

After his stint in prison, Emino released a new song. “Tunisia destroyed my dreams. It’s not a country of freedom of expression. I’m going to go on vacation to change my mind,” he rapped on it, in Arabic. That vacation turned out to be in Turkey, notorious for being the gateway to Syria for the majority of would-be jihadis and a hotbed for ISIS recruiters.

“When he returned from Turkey, he began to pray and go to the mosque. His friends were shocked. They didn’t recognize him anymore. They said, ‘Emino has changed’," according to Tunisian news station El Hiwar al-Tounisi.

Around that time, al-Dwiri and a rapper known as Weld el 15 also collaborated on a song called "Boulicia Kleb” (Cops Are Dogs). That got them arrested again. The actress and cameraman for the music video were sentenced to a year in prison; al-Dwiri and Weld were each sentenced to two years, but reportedly fled before being taken to prison.

"Both rappers are in hiding and were still releasing songs and videos. Cops are looking for them and the interior ministry wants them to turn themselves in," Mashhadi said at the time, in 2013. “The most wanted [men] in Tunisia are not rebels, not corrupt politicians, not murderers. They are rappers,” he added sarcastically.

Weld told International Business Times he now lives in France where he said he is working on “an artistic project.” He refused to comment on his prison sentence, but his Facebook profile picture shows him and al-Dwiri together, before the latter joined ISIS. Days after al-Dwiri reappeared on social media from the so-called ISIS caliphate,Weld wrote on his Facebook page that despite being against jihad, al-Dwiri would always be his friend. Al-Dwiri did not respond to requests to be interviewed for this story.

“Prison is the perfect place to create a terrorist because what prison does is create a very black and white world,” said Arun Kundnani, a professor at New York University and author of "The Muslims are Coming! Islamophobia, Extremism, and the Domestic War on Terror." “That’s the mindset you need if you’re going to be a terrorist. To the extent that we put people in prison who weren’t going to be a terrorist, we’re certainly encouraging a situation in which that that could be the outcome that results.”

In Tunisia, a country with prisons at 138.9 percent capacity and with the highest number of people per capita who have joined ISIS, the mix of overcrowding and ISIS contacts in the nation’s jails makes them fertile ground for recruitment.

Three-thousand to 4,000 Tunisians have joined ISIS, and many who came back with the possible intention of carrying out attacks in the country have been jailed. In October, the Interior Ministry said 450 to 500 had returned, a third of them subsequently jailed. That means Tunisian prisons now house at least 150 hardened jihadi fighters who have been in Syria and are eager to make converts.

Once inside prison, these newly returned ISIS fighters mix with people who perhaps had never thought about joining the radical group, but, like al-Dwiri, may have a grudge against the government. The ISIS men help them survive life in prison and maybe even plot revenge. And in the case of ISIS, the recruiter will demand one thing in return: allegiance.

“Prisons the world over are run by organized gangs of prisoners. It’s a common phenomenon. If not Islamists or communists, it’s the Aryan Brotherhood,” said Peter B. Zinoman, a professor at the University of California, Berkeley, who has written several books on radicalization in prisons throughout history. “It’s a recurring feature that tightly organized groups of prisoners are a very important mechanism of protection and solidarity for the prisoners inside the walls.”

Before his run-in with the government, al-Dwiri had a promising music career ahead of him, a rare thing in a country where nearly 40 percent of youth are unemployed. Many young men spend their days sitting on plastic chairs outside cafes and hookah bars, with nothing to do. Those who turn to Islam as a solace risk running afoul of a crackdown on public displays of religiousness and being accused of being radical.

“For many of these young men, death in Syria is a lot better option than staying here and going to prison, and being tortured and harassed,” Marwen Jedda, a human rights lawyer who represents many Islamist clients, told the Washington Post.

Secularism had been strictly enforced in the Muslim-majority country for decades under former President Zine El Abidine Ben Ali. The 2011 revolution that sparked the Arab Spring and ousted Ben Ali ushered in what is widely seen as the most stable government to come out of the upheavals in the Arab world -- but jihadist group Ansar al-Sharia had gained such a foothold in the country, the government resorted to strict security measures to quell the rise of Islamist extremism.

Yet the Tunisian state’s low tolerance for those who speak out against it, while it may not lead to the repression of dissent seen under Ben Ali, could also help create the exact problem the Tunisian state is hoping to avoid.

“It creates an atmosphere in which generally among young Muslims there will be a perception that the system is weighted against them and that it operates through various kinds of racism,” Kundnani said. “That makes the recruiter’s job easier.”

Al-Dwiri is now allegedly with ISIS in Iraq. Pictures of him with various known ISIS members circulated on social media in the last week, and the group’s members hailed his presence in the so-called caliphate. In many pictures he is seen eating and enjoying himself with “friends.” In one photo, he is in a bakery with three other alleged ISIS members; one of them is likely the same fighter photographed pulling Jordanian pilot Muath al-Kaseasbeh out of the water when his fighter jet crashed in Syria last December. ISIS later burned al-Kaseasbeh to death.

He has been spotted in many other photos, including with an alleged ISIS fighter named Zief Supras, the man who the Tunisian government says helped al-Dwiri get to the so-called caliphate. Contacted by IBTimes on Facebook, Supras said al-Dwiri was with him and he was happy but would not speak to a reporter.

“He forgot his past,” Supras said. “He hates his old life.”