Tunisian pastry chef Slim Gasmi died on a Syrian battlefield and was lionized with a hashtag: #martyrdomofabuqatada.

Gasmi, 28, had been trying to build a life for himself and his new fiancee in a working-class Tunis neighborhood, but a radical Islamist roommate persuaded him to travel to Syria to fight in that country’s civil war. By the time he was killed in April more than 1,500 miles from home, he had transformed into a warrior with a long beard and a nom de guerre, Abu Qatada, celebrated on a radical jihadist Twitter feed.

Tunisia, a small North African country of 11 million people, has become the largest source of foreign fighters joining the Islamic State and other extremist groups in Syria and Iraq, according to estimates by the Tunisian government and private analysts.

As many as 3,000 Tunisians, most of them men under 30, have joined the battle, placing this popular Mediterranean tourist destination higher than even Saudi Arabia and Jordan on the list of the homelands of the 15,000 or so foreigners fighting with the Islamic State and other radical militant groups.

That flow of Tunisian fighters is partly an unintended consequence of the Arab Spring uprising in 2011 that overthrew longtime dictator Zine el-Abidine Ben Ali and touched off popular revolutions across the region.

Map: Flow of foreign fighters to Syria

The moderate, Islamist-led government elected after the revolution granted new religious freedom after a half-century of harshly enforced secularism, when the state banned women’s veils and almost all other displays of piety and jailed thousands of people it suspected of holding Islamist beliefs.

That freedom was quickly exploited by Islamist radicals, who killed two politicians and at least 25 police officers and soldiers, and used newly free mosques to incite a rising tide of violence that now reaches as far as Islamic State strongholds in Syria and Iraq.

Faced with sudden bloodshed in a country that had long been a calm, European-style oasis wedged between chaotic Libya and Algeria, the post-revolution government has struggled to balance religious freedom and public security.

Human rights organizations and lawyers say the government has overemphasized security, creating a climate of repression and anger that is fueling the flow of Tunisian fighters to the Islamic State.

“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,” said Marwen Jedda, a human rights lawyer who represents many Islamist clients.

In a country that is 99 percent Muslim, the government has banned more than 150 Muslim civic organizations, closed a radio station and arrested at least 2,000 young people on terrorism charges. Rights advocates say the government is engaging in the same arbitrary arrests and systematic torture of prisoners practiced by Ben Ali’s brutal regime, in power from 1987 to 2011.

Government officials deny that security forces use widespread torture but say they are being tough to protect the country from violent radicals who took advantage of their new freedoms.

“We gave them too much oxygen, and now we are choking on that oxygen,” Interior Minister Lotfi Ben Jeddou, who is in charge of Tunisia’s security, said in an interview.

Tunisia’s ‘holy warriors’

Tunisia has a long history of sending “holy warriors” to fight in Gaza, Afghanistan, Chechnya and Iraq. Analysts here said that for many years Ben Ali tacitly encouraged them to go overseas, preferring that they commit their violence far from the tree-lined boulevards and sidewalk cafes of Tunis.

But the flow to Syria, and particularly to the Islamic State — the brutal group that recently beheaded two U.S. journalists and two British aid workers — is the largest exodus of fighters in Tunisia’s history.

The government is waging a campaign using billboards to remind people of Tunisia’s traditionally moderate brand of Islam. The billboards read “Terrorism is not ours.”

“I talk about this all the time during Friday prayers,” said Imam Arbi Zitoun of the Sidi Youssef Dey Mosque in Tunis. “I tell people that going to Syria is like killing yourself. That is not the Islam of Tunisia.”

In interviews here, the families of several men who traveled to Syria to fight said they went partly because of poor economic conditions, noting that Tunisian unemployment is high and the Islamic State pays its fighters a salary. But they said a far greater motivation was a sense that Tunisia’s government, even after the revolution, is hostile to its own Muslim population. They said frustrated young men are being radicalized in mosques and on the Internet, often by preachers and recruiters from, or paid by patrons in, Saudi Arabia, Qatar or other Persian Gulf states.

“Young people are thirsty for religion, and they are looking for identity and meaning in their lives, and when someone shows up and offers that, they are impressed and will follow that person,” said Mahfoudh Balti, whose 21-year-old son, who was studying to be an electrician, went to fight in Syria two years ago.

“The lack of religious freedoms in Tunisia influenced my son, because now if you pray in a mosque they accuse you of terrorism,” Balti said. “By preventing these young men from praying, it pushes them another way.”

Balti said his son, whom he declined to identify by name, became disillusioned when he arrived in Syria and saw Muslim groups fighting one another instead of the forces of President Bashar al-Assad. He said his son never fought with any group and remains in hiding in Aleppo, Syria, unable to return home because he knows he would be arrested and charged with terrorism.

Jeddou, the interior minister, said between 450 and 500 Tunisian men have returned and about a third of them are in jail. The government is closely monitoring the rest, hoping that they might lead officials to networks involved in radicalizing young people and sending them to fight.

Monia Bouali, 43, a Tunis lawyer, said that when she was 15, she was jailed for two weeks for wearing a head scarf to school. She was thrown out of her public school and blocked by Ben Ali’s regime from going to medical school, and she sees the same pattern being repeated even after the ­pro-democracy revolution.

“So far, the government is only dealing with these young people on the security level, and that’s a big mistake,” she said. “You can’t oppress them for being Muslim, because this is a Muslim society. You need to allow them to express themselves and to be involved in civil-society organizations.

“If you oppress religion, it will rise again in another shape,” she said.

New freedom for Islamists

In October 2011, Tunisia elected its first post-revolution government, led by the moderate Islamist Ennahda party. But that government resigned in January over its inability to complete a new constitution and amid criticism that its failure to control its most extreme supporters had led to the rise in violence.

A caretaker government was installed, finished the constitution and oversaw parliamentary elections held Sunday, in which Ennahda finished second to the secular Nidaa Tounes party. Presidential elections will be held next month.

Jeddou said the Ennahda government initially tried to allow Islamists to organize and be part of society. He said officials allowed the Islamist group Ansar al-Sharia, formed by some of the 3,000 men released from Tunisian prisons immediately after the revolution, to hold public meetings and do social work in poor neighborhoods.

But by the end of 2012, he said, “they showed their true face.”

He blamed Ansar al-Sharia for the assassinations of two opposition politicians in 2012, and for the September 2012 attacks on the U.S. Embassy and an American school, among other acts of violence.

The U.S. government has categorized Ansar al-Sharia as a terrorist organization. Its founder is one of the men released from prison, Saif Allah bin Hussein, better known as Abu Ayyad, a veteran jihadist who fought in Afghanistan with Osama bin Laden.

The government banned the group in August 2013 and made membership a crime. Pushing the group underground has led to even more violence, including an attack on Jeddou’s home in May that killed several guards.

Jeddou said security forces have tortured some suspects, but he called those individual “lapses,” not a policy. He said that under Ben Ali, torture was systematically used against political enemies and involved doctors advising torturers on the most effective techniques. He said his ministry is working to eradicate torture but “we are still in a period of transition.”

He said the government knows of 2,560 Tunisians who have gone to fight in Syria, at least 80 percent of them with the Islamic State. He said the actual number was probably closer to 3,000. Of those, he said, 450 have been killed and 60 are being held in the Assad government’s prisons.

He said the Tunisian government has stopped 9,000 more from going to Syria, catching them either at the Tunis airport or at border crossings into Libya or Algeria. Jeddou said a small percentage of those going to fight with the Islamic State are educated professionals. The vast majority, he said, are “not sophisticated people, with limited education and social problems.”

‘The land of jihad’

Slim Gasmi was born and raised in the southern desert town of Tataouine, where parts of the “Star Wars” movies were filmed, then moved to Tunis after dropping out of high school.

When he couldn’t find work after his vocational-school training as a pastry chef, he left for Libya to look for a job. He had relatives there and quickly found work with a food wholesaler. He started saving money for his marriage and came home every few weeks to visit his fiancee in Tunis.

His sister, Latifa, first noticed changes when he visited in June 2013. He had never been particularly religious, but now he grew his beard and told his sister that he was thinking of going to Syria to fight because “people in Syria are suffering, and we need to help them.”

The family suspected the influence of Gasmi’s new roommate in Libya, another Tunisian man who was far more religious. They also feared that in Libya he had ­encountered proselytizers from Saudi Arabia or other Persian Gulf countries who had recruited him to fight in Syria.

On the phone, he started repeating a phrase that his family found chilling and out of character: “The land of Levant is the land of jihad.”

Latifa said she pleaded with him: “If you want to be a good person, you don’t kill people. If you come home and teach people the Koran, that’s doing jihad, too. You don’t have to go to Syria to kill people to do jihad.”

On New Year’s Eve in 2013, he called home to say he was in Turkey and about to cross into Syria. Latifa, in tears, begged him not to go, but he told her not to worry.

A month later he called his brother, Tijani, to say he was in an Islamic State camp near Aleppo, Syria. His brother started crying and told him to come home. Gasmi started crying, too, and said that he wanted to leave but couldn’t because the militants had taken his passport and wouldn’t let him go.

He told his brother that he didn’t like the bloody infighting among competing Islamist forces in Syria.

“I’m not here to kill people, I’m here to help people,” he said.

The family didn’t hear from him again until late March, when he contacted his fiancee on Facebook. He seemed depressed, and his message was cryptic: “I can’t tell you anything,” he said. “I want to talk to you but I can’t.” He ended the message with a sad-face emoticon.

On April 1, Gasmi’s aunt called the last number from which he had called. A man answered, and she asked to speak to Slim.

“First of all, his name is not Slim,” the man said. “It’s Abu Qatada. And Abu Qatada was martyred today. We have already had a funeral for him and buried him.”

The next day, a photo of Gasmi’s body, with his new martyr’s hashtag, was posted on Twitter by an al-Qaeda affiliate known as Jabhat al-Nusra. It showed him lying on a field stretcher, his face bruised and lined with dried blood. His eyes and mouth were half-open.

The photo also appeared on a Facebook page maintained by the group. There, one commenter said Gasmi had fled the Islamic State but was stopped at a Jabhat al-Nusra checkpoint, where he was taken into custody and forced to join the group. It said he was killed in battle.

“He was just naive. He didn’t know what he was doing over there,” said his uncle, Ahmed Lahmar. “Tunisian men are being sold as sheep.”