SOUSSE, Tunisia—Terrorism is not Tunisian, the refrain of the moment goes. Except it was on Friday. Just before noon, Seifeddine Rezgui, a 23-year-old Tunisian, pulled a Kalashnikov out of an umbrella and murdered 38 tourists on the beach here, maiming dozens of others with his rifle and grenades before being gunned down by Tunisian security forces. ISIS soon claimed responsibility for the attack, releasing photos of Rezgui wielding weapons and calling him Abu Yahya al-Qayrawani.

Four years ago, a popular revolution in Tunisia, the first of the Arab Spring’s uprisings, removed the authoritarian government of Zine El-Abidine Ben Ali, which had controlled the country for decades. Since then, the North African nation has been heralded as the Arab Spring’s sole success, a newborn democracy enjoying civil liberties, and political moderation and inclusion, that exist only as trampled dreams in Egypt, Libya, and Syria. But extremism is filling out the edges of this picture. Friday’s attack came just months after two gunmen killed 22 people at the Bardo Museum in Tunis. Analysts estimate that at least 3,000 Tunisians have joined militant groups in Syria, with most fighting for ISIS. How has the region’s relative sanctuary of stability also become the world’s top supplier of foreign fighters to the conflicts in Syria and Iraq? Is Tunisia’s hard-earned stability only now being tested, or has that stability been precarious and illusory all along?

“God knows how this happened,” said Hajer Kechiche Dandana, a 40-year-old accountant, as she held her sister Iman’s hand at Sousse’s Sahloul Hospital. Iman, 34, was working in the Imperial Marhaba Hotel’s administrative office when Rezgui began his killing spree at the beachfront establishment. She was injured in her left hip, arms, and knees by a grenade, but spared when Rezgui pointed his gun in her face and she begged him in Arabic not to shoot. The attacker was clearly targeting foreign tourists, not Tunisians, she said. Lying in the hospital bed, she closed her eyes when asked about the killer’s face, squeezing her sister’s hand.

“Iman doesn’t want to remember it,” Dandana quickly said. “We don’t know how these guys got their minds messed up. Inshallah the attacks will stop, but we’re afraid. We feel like it will happen again.”

On Saturday night, less than 48 hours after the attack, thousands of people marched across Sousse, waving flags, singing, and chanting slogans like, “Tunisia in freedom, terrorism get out” and, “With soul, with blood, we will protect the flag.”

“Look, this is Tunisia,” said Mohamad Habib Snoussi, a 67-year-old schoolteacher, as he swept an arm toward overflowing cafes at 11:30 p.m., after the day’s Ramadan fast had concluded. “Terrorism will not grow because Tunisians love life. … We hate this terror that is coming from outside, and we will fight it together.”

But unity is a challenge in Tunisia, where democratic transition has brought unprecedented pluralism in political and social spheres alike. Under Ben Ali’s regime, free expression and Islamist movements were violently suppressed. Post-revolution, Tunisia’s newfound liberty has birthed two free and fair elections, but also four years of obstreperous debate on everything from the wording of the new constitution to the role of Islam in a democracy. “We are moving from one party to a hundred,” Snoussi said. “It’s hard to agree.”

The Democracy Report

The first post-revolution government was led by Ennahda, a moderate Islamist party that promised religious fidelity alongside pragmatic governance. Its leaders were also loosely tolerant of Salafi groups like Ansar al-Sharia, which advocates for a strict interpretation of Islam that includes caliphate rule and sharia law, not a democratic, constitutional state. The Ennahda government outlawed Ansar al-Sharia after the group assassinated two leftist politicians in 2013, but critics blame Ennahda for allowing Salafism to spread in the country to begin with.

Last October, Nidaa Tounes, a secular party whose leaders have ties to the Ben Ali regime, replaced Ennahda in power, but the Islamist party remains a critical part of Tunisia’s governing coalition.

A demonstration against terrorism in Sousse, Tunisia (Zohra Bensemra / Reuters)

Several politicians joined Saturday’s march in Sousse, including Mohsen Marzouk, a founding member of Nidaa Tounes and the campaign manager for Tunisia’s current president. “We are trying to organize people in the war against terror,” Marzouk said, adding that the government wants to mobilize the population to inform intelligence officials about terrorist activity. “This war is not between terrorists and the state, but between terrorists and the people.”

But the people could use more help from the state. Tunisian leaders promised tightened security and a crackdown on illegal mosques (those inciting terrorism) after the Bardo attack in March. Yet those pledges didn’t prevent or mitigate Friday’s terrorist attack, the deadliest in the country’s recent history. When the prime minister announced a series of security measures in response to the massacre in Sousse, Tunisian social-media users reacted with biting skepticism. “2 attacks in 4 months on 2 places supposed to be under surveillance. Nearly 60 dead. 0 resignations. No challenge to the govt,” one observed.

As busloads of foreigners evacuated from Sousse’s tourist resorts on Friday and Saturday, Salim Qamuma, a 50-year-old taxi driver, waited outside the hotels for hours without a customer.

“We had some tourists stay after [the] Bardo [attack], but now it’s over,” Qamuma said. Extremist groups were deliberately striking the tourism sector, he added, so that Tunisia’s already faltering economy would collapse. “They want chaos. They want us [to be] like Libya. They want to make people poor and hungry so they can take over.” How, he wondered, will the government control Tunisia’s nearly 290-mile border with Libya, where the Bardo attackers reportedly trained? How can it silence Salafi preachers when free speech is now protected in the constitution?

“We had no religious consciousness under [former President Habib] Bourguiba and Ben Ali,” said Anouar Jamaoui, a Tunisian academic based in Sousse. The previous authoritarian regime had maintained absolute control over all aspects of Tunisian life, including the religious sphere. “People were frustrated, lost, unable to know more about their own religion. They wanted to be Muslims but didn’t understand what that meant,” he explained. The opening of public space for religious discussion has come faster than the public’s ability to decipher and interpret Islamic teachings for themselves, Jamaoui added. After decades of paltry religious education—“We had two hours a week of Islamic education in secondary schools under Ben Ali”—Tunisian religious identity can suddenly be freely defined.

“The voice of moderate Islam is the Tunisian people,” Jamaoui said, adding that Tunisian Islam has always been wasatiyya, or moderate. This is the time for Tunisians to make it democratic as well—to meld Islam and democracy in a model that in many ways is the antithesis of ISIS’s caliphate—but they’re doing so amid a cacophonous debate about the nature of Islam and its role in society, charged with the emotion and suffering of regional conflicts. Meanwhile, Tunisia’s post-revolution politicians have been wary of silencing Islamist voices, even dangerously radical ones, because Ben Ali’s regime so severely oppressed them as dissidents alongside leftists and liberals.

Now the debate has turned violent. For many Tunisians, exhaustion and fear of radicalism have replaced the initial exhilaration of self-determination.

“Ben Ali wouldn’t have stood for this. He wouldn’t have let [the Salafis] speak a sentence,” said Qamuma, the taxi driver. “You couldn’t even grow a beard under the old regime, but nothing like this happened. Look what freedom has brought us: terrorism on the beach. This isn’t freedom, it’s death.”

At the demonstration against terrorism, one elderly history professor paused on the sidewalk as a group of teenagers marched by, howling a local soccer team’s song as they waved Tunisian flags in the air. “We are 11 million Tunisians with 11 million Islams, and everyone says theirs is the right one,” the professor, who gave his name only as Waled, murmured. Young people especially don’t know what they believe, he added, but who does? Tunisia is against terrorism, he observed, and yet: “Le ver est dans le fruit.” The worm is inside the fruit.

A member of Tunisia's special forces inspects the beachside of the Imperial Marhaba resort. (Zohra Bensemra / Reuters)

The government recently proposed a new law that would support victims of terrorism and task a commission with developing a counterterrorism strategy. But the law would also allow extended detention, chip away at legal due process for terrorism suspects, and permit the death penalty for anyone convicted of a deadly act of terrorism, though a moratorium on executions has been in place in Tunisia since 1991. After Friday’s attack, the prime minister announced that the law would be adopted by late July. International human-rights organizations and Tunisian civil-society leaders have protested that the law threatens fundamental human rights. Qamuma’s comments aside: Many Tunisians want security, but not at the cost of freedom.

“Terrorists want to make an end to Tunisia because it is the only true democratic model in the Arab and Muslim world,” said Jamaoui. “They are targeting the democratic experiment in Tunisia.” The attackers’ strategy is smart, Jamaoui noted, because it is sowing tension between Tunisia’s state, police, and people.

Tunisia’s struggles to counter terrorism and nurture democracy are intertwined and, at times, mutually destructive. Terrorism spurs the state to prioritize security, but that threatens liberty and popular trust in the government. The damage extremists inflict on the vital tourism sector weakens people’s faith in the state even more, especially as unemployment and corruption go unaddressed. (A recent OECD report described the country’s youth unemployment rate, which hovers around 40 percent, as a “true social tragedy,” while a World Bank paper suggested that the revolution has “democratize[d] corruption in Tunisia.”) Tunisia’s leaders must fix the economy, but first they must build a voter base and coalition. All this takes time. In the meantime, people—especially young people—lose heart.

At the march against terrorism, Lassaad Ben Hassen, a 28-year-old painter and handyman, said he doesn’t vote and most of his peers don’t either. “The parties don’t do anything for me, so I do nothing for them,” Ben Hassen said. Instead of improving people’s daily lives, he added, the revolution only exacerbated the wealth gap between rich and poor. “Maybe it’s a mistake for me not to vote. But when you see the politicians’ empty talk, you don’t believe or want to vote for anyone.”

Zied Touzani, the president and founder of Tun’Act, an organization that promotes youth political engagement, pointed out that young people make up more than half of Tunisia’s population, but they’ve grown increasingly disillusioned with post-revolution politics. When Mohamed Bouazizi, a 26-year-old Tunisian street vendor, set himself on fire in 2010, precipitating the Arab Spring, it was in protest of police harassment that not only obstructed his meager livelihood of selling vegetables, but also stole his dignity. Four and a half years later, democracy has answered Tunisians’ cry for freedom, but little has changed economically.

“It’s nice to have freedom of speech, but what we’re looking for is jobs,” Touzani said. As Tunisia’s economic problems persist, frustrated youth either change their vote from party to party, or disengage altogether. “Young people drove the revolution, that’s true. But where are they now?” Touzani asked.

In the capital, Tunis, young Tunisians flock every night to a popular villa remodeled into a hostel and bar. They drink mojitos (virgin during Ramadan), play popular music, and sport sundresses, tattoos, and dreadlocks. “Most of the people here are, like, artists, or they work for NGOs,” one girl told me over the crowd’s noise. She laughed at the idea that Tunisia is the Arab Spring’s success story. “What a joke. We’re great compared to Libya and Syria, but what are you comparing us to?”

Many young people are drawn to civil society, Touzani said. Civil-society organizations are “seen as legitimate because NGOs and human-rights groups aren’t running for their own power. They’re protecting civil rights and principles.” But others turn elsewhere: to boats of migrants crossing the Mediterranean, or to informal mosques offering an altogether different worldview—and then perhaps to Islamic extremist groups in Iraq and Syria.

“We have to make youth loyal to political parties instead of extremist organizations,” said Jamaoui. Yet political engagement is a tough sell when people don’t have jobs, bread, water, or hope. Tunisians are engaged in a national conversation about balancing security and liberty, democracy and Islam, politics and civil society. It’s a critical dialogue, but Tunisians need their basic needs met so they can keep participating.

“We have potential to be a success story,” said Touzani. “But not yet.”

Reporting for this article was supported by the Pulitzer Center on Crisis Reporting.