Soon after Islamist militants gunned down 21 foreign tourists in Tunisia's Bardo museum last month, newspaper columnists, radio hosts and politicians swiftly called for a merciless crackdown to save their young democracy.

In the cafes and mosques of working-class Tunis, fears are now emerging that a campaign against militants may a spiral into repression like the old days of Tunisia's police state before the freedoms won in a 2011 revolt.

Tunisia has since been held up as a model of democratic transition, the only country where an uprising during what came to be known as the “Arab Spring” did not end in large scale violence or civil war.

But last month's attack is testing Tunisia's tricky balance between security and the new liberties since the revolt, which ousted long-running autocrat Zine El-Abidine Ben Ali.

Lawyers, opposition leaders and rights campaigners say they have seen more arbitrary arrests and police harassment, and worry a proposed anti-terror law will roll back freedoms as lawmakers yield to public opinion.

In poor Tunis quarters, some religiously conservative young men say they are shaving off their beards, eschewing traditional gowns and limiting mosque visits to avoid harassment from police who they fear will sweep up anyone who even looks militant.

“The atmosphere has changed. I shaved off my beard because I don't want to be watched by the police,” said Moez, a religiously conservative salesman. “Even I am against terrorism or any extremism that damages Islam's image.”

Four years after its revolt, Tunisia is unlikely to slide back to the days of Ben Ali's oppressive state. It has free elections, a new constitution and a political environment that sees compromise deal-making between secular and Islamist politicians.

But the Bardo attack complicates already tricky questions over religious freedom in one of the Arab world's most secular nations, where liberal lifestyles often sit uneasily alongside a strain of conservative Salafist Islam.

“There are a lot of constraints on rights in this atmosphere of anger after the attacks,” said Yamina Zoglami, a lawmaker from the moderate Islamist party Ennahda. “Yes, Tunisia has been hit hard, but we can't let that hurt our rights and freedoms.”

Since its transition to democracy, Tunisia has been praised by the West as a symbol of democratic hope for a region where other “Arab Spring” nations are caught up in division, intolerance and outright war.

But the small North African state has also struggled to define the role of Islam in politics, especially with the rise of ultra-conservative Islamist and Salafist groups who emerged with the new freedoms.

Security is key for Tunisia's vital tourism industry. So far the government estimates the impact of the Bardo attack on foreign visitor bookings appears slight, though the summer season has yet to start.

Prime Minister Habib Essib told parliament this week authorities would increase their campaign to take back mosques controlled by extremists who the government blames for helping recruit young men into militant groups.

“We respect freedoms, this is not about falling into a police state,” President Beji Caid Essebsi told Le Monde newspaper. “But when someone comes to kill you, and kill those around you, you have a state of legitimate defense.”

Tough anti-terror talk

Human rights groups are worried.

“All these declarations are quite disturbing,” Amna Guellali director of the Human Rights Watch Tunisia. “There will be some fallout in widening the net of arrests, we don't know whether this goes beyond that yet.”

One immediate concern is the newly proposed anti-terrorism law that will be debated in the national assembly. The draft extends some police powers such as pre-trial detention time, and lifts a halt on death penalty.

Human Rights Watch has urged the government to revise the draft. The rights group said the bill allows police to hold detainees for up to 15 days before they go before a judge. It also has a broad definition of “terrorist” activity, opening the way for abuses.

Fear of repression falls mostly on conservative Salafists and Islamists who were long oppressed by Ben Ali and by his predecessor Habib Bourguiba, seen as the founder of much of Tunisia's secular tradition.

While Salafists, who model their austere lifestyle on the Prophet Mohammad, share some of the same religious outlook as hardline jihadists, most reject their violence.

But their drive for a broader role for religion in public life has often alarmed Tunisian secularists who fear this could undermine individual freedoms and women's rights.

In the tumultuous days after the 2011 uprising, Salafist hardliners attacked theaters and art shows and other symbols they saw as un-Islamic. Extremist imams took over mosques and set up Koranic schools.

Even before the Bardo attack, the government had begun a broad crackdown on suspected militants and brought mosques back under the control of the ministry of religion. That process has widened, say lawyers and rights campaigners.

“Now we are seeing people arrested just because of the way they look,” Anouar Aouled Ali, a lawyer who has defended suspected jihadists and Salafists. “There is a panic, we are creating terrorism, not fighting it.”

Ridha Bel Hadj, from the moderate Salafist party Hezb Ettahrir, said a crackdown could spur more radicalism.

“All this is a threat to the principles of the revolution and turning us back to a darker time,” he said. “The danger is if you continue with this campaign, it will create more anger and reactions from our Islamist youth.”

A slide into Ben Ali-style oppression is still unlikely. Ruling secular party Nidaa Tounes governs in a coalition that includes Ennahda, the Islamist party that won the first post-uprising election. That compromise may keep those calling for more repressive measures in check.

“We're not going back to the past of Ben Ali, we can't do that,” said one Tunisian security official. “Democracy is here to stay and it is stronger than ever.”