Allan Bredy, the director of the American Cooperative School of Tunis, stands on Sept. 16, 2012 in one of the early elementary classrooms of the American school in Tunis, Tunisia that was torched and looted by a mob during protests triggered by a privately-made American video that mocked Islam.  (Karin Brulliard/The Washington Post)

Onlookers milled and nervous merchants shut shops as security forces surrounded a colonnaded mosque on a leafy downtown street here on Monday, preparing to arrest a man giving a speech inside.

Hours later, the officers had retreated, and the speaker, a hard-line Islamist whom Tunisian authorities say instigated a violent rampage at the U.S. Embassy last Friday, had slipped away.

And so the hunt for one of Tunisia’s most-wanted men continued, raising questions about the will of the government to rein in ultra-conservative Muslims who vociferously — and sometimes violently — oppose plans to build democracy in this nation whose revolution sparked the Arab Spring.

Those questions have become a defining battle of the democratic transition in tiny Tunisia, and the embassy attack dramatically raised the stakes. Handling the fallout of the deadly demonstration, one of several connected to anger over an American-made YouTube video insulting Islam, is now posing a major test for a country that has been lauded for its smooth post-revolution shift.

Tunisia’s new government, led by the moderate Islamist party Ennahda, has pledged to demonstrate that the country’s traditionally tolerant brand of Islam is compatible with Western-style democracy. But it has also struggled to balance the interests of pious Muslims relishing newfound religious freedoms, secular Tunisians who are spooked by Islamists and the United States, which provides crucial economic assistance.

Many here agree that the equation failed last Friday, when mobs set fire to the embassy and a nearby American school, prompting the United States to withdraw most diplomats and warn travelers away from tourism-dependent Tunisia.

As in Libya and Egypt, where demonstrations against the video at U.S. missions also turned violent, officials and participants said the protest here was hijacked by extremists and exploited by hooligans. But it was also viewed domestically as only the most violent in an escalating series of thuggish acts by ultraconservative Islamists, known here as Salafists, against uncovered women, art, bars and other things they deem un-Islamic.

The governing coalition, which includes two secular parties, has sought to avoid ideological confrontations during the transition to democracy. Analysts say that is particularly true of Ennahda, whose leaders have championed the return of Islamic values to Tunisia but are viewed by some secularists as closeted radicals and by Salafists as religious poseurs.

The embassy attack, which left four Tunisians dead, and the U.S. reaction have clearly rattled the government. Officials have condemned what they say were the actions of a tiny minority and vowed that the failure to protect the embassy and school — which some attributed to poor planning, others to divisions within security forces — will not happen again.

“There was an obsession with the right to demonstrate and the right to be within a republic that protects the rights of the citizen, whoever they are and whatever they believe,” said Hedi Ben Abbas, a Tunisian undersecretary of state for foreign affairs who blamed the violence on Salafists. The embassy attack, he said, “was, for us, the end of the game.”

This week, Tunisian military vehicles and soldiers guarded the charred American buildings, and the United States deployed additional security to embassy premises. Khaled Tarouch, an Interior Ministry spokesman, said Tuesday that 96 people had been arrested in connection with the attack.

Police for days said they were pursuing prominent Salafist leader Saif Allah bin Hussein, known as Abu Ayyad. He is the leader of the Tunisia wing of Ansar al-Sharia, a radical Islamist group that is loosely tied to the group of the same name in Libya whose members have been implicated by Libyan authorities in the attack there that killed U.S. Ambassador to Libya J. Christopher Stevens. Abu Ayyad was imprisoned under the former Tunisian dictatorship and released under an amnesty deal after the 2011 revolution.

Despite being a wanted man, on Monday he felt emboldened enough to deliver a sermon at the central al-Fatah mosque. He commanded supporters to protest peacefully and railed against what he called a “new dictatorship” that discriminates against Islamists. Tarouch said police eventually retreated to avert a violent confrontation in a crowded location.

“How long will the government play cat and mouse with the Salafists?” La Presse, a Tunisian daily newspaper, editorialized the next day.

“No one has been able to convince the government that there is a danger behind this and Tunisian society would never accept such an atmosphere,” said Ahmed Ounaies, a retired diplomat who briefly served as foreign minister after the revolution.

Lofti Zeitoun, an adviser to the Ennadha prime minister, said security forces are stepping up surveillance and “dismemberment” of extremist groups. But he said a harsh crackdown early in Tunisia’s transition could drive radicals underground, alienating those who could still be convinced by democracy.

“American support for the Arab spring is one of the most important guarantees for the success of this democratic transition,” Zeitoun said. “If we are left alone, maybe we will go to a new kind of dictatorship, a dictatorship of chaos and mobs.”

The video offended many Tunisians, said Yassine Brahim, one leader of a liberal opposition party that also called for a demonstration against it. But so did the violent reaction, said Brahim, who, like many here, said it was “not Tunisian.”

Among those who protested the video was Walid, a 32-year-old trader who sat in the pink twilight outside a mosque in southwest Tunis on Monday. Hours before, he was in al-Fatah mosque listening to Abu Ayyad; three days before, he was outside the U.S. Embassy, condemning the offensive video and what he called an American mission to destroy Islam.

Walid, who declined to give his last name, blamed secular and former regime forces — wearing “fake beards,” he said — for stirring the violence to frame Salafists. But he said he did not regret the death of Stevens. Arresting Abu Ayyad, he said, would spark a “human catastrophe.” As for Ennahda, Walid said he doesn’t consider the party to be truly Islamist, and he opposes democracy in Tunisia because only Sharia, or Islamic law, pleases God.

Even if the government curbs law-breaking by extremists, no one here thinks it will settle broader questions about the role of Islam in Tunisian democracy.

The government says it is dedicated to freedom of expression, but it is facing growing criticism from civil society groups and international human rights organizations about restrictions.

Rachid Ghannouchi, Ennadha’s spiritual leader, said the violence at the embassy was un-Islamic, and he said his party is trying to convince extremists that “their ideas are wrong.” But he said that in an increasingly globalized world, there should be international laws against speech that incites on the basis of religion, something Ennadha is advocating in Tunisia, to the dismay of many secular groups.

“For us to live in a civilized, peaceful world, we need to put some limits on freedom,” Ghannouchi said. “What happened may give support to our cause.”