Police officers patrol the beach in Sousse, Tunisia, on June 30, four days after Friday's terrorist attack, which killed at least 38 people. (Abdeljalil Bounhar/AP)

— Tunisian authorities have promised to shut extremist mosques, squeeze terrorists’ ­access to funds and call up army reserves. They are also promoting sweeping new anti-terrorism legislation.

The measures are in response to attacks on security personnel and massacres of tourists — including the rampage by a Tunisian gunman at a beach resort Friday, which claimed the lives of at least 38 people.

But while the Tunisian public is demanding a tough response to the terrorist acts, human rights groups, civic activists and some politicians worry that the new measures could weaken the lone democracy that has emerged from the Arab Spring protests.

“I think the risk at this moment is overreacting to this threat and compromising our civil liberties and human rights,” said Sayida Ounissi, a parliamentarian from Ennahda, a moderate Islamist party. “We can’t let this happen.”

Tunisia is a rarity in the Arab world. Other countries in the region that experienced mass uprisings against autocratic rulers — such as Egypt, Syria, Libya and Yemen — either have returned to authoritarian rule or descended into civil war.

Mourners lay flowers on Marhaba beach, where at least 38 people were killed in a terrorist attack, on June 30 in Sousse, Tunisia. (Jeff J. Mitchell/Getty Images)

Tunisia, in contrast, has had several free and fair elections since the overthrow of longtime dictator Zine el-Abidine Ben Ali in 2011. Last year, after lengthy debate between Islamist and ­secularist lawmakers, Tunisia passed a constitution seen as one of the most liberal in the Arab world, winning praise from human rights groups.

But this North African country faces a growing threat from extremist groups, which intensified their recruiting after the collapse of Ben Ali’s police state. Meanwhile, offshoots of the Islamic State and al-Qaeda have established themselves in neighboring Libya. A senior Tunisian security official, Rafik Chelli, told the Associated Press on Tuesday that the gunman in Friday’s attack had traveled to Libya in January and gotten training there.

Thousands of Tunisians also have left for Syria and Iraq to join groups including the Islamic State, and hundreds of them are believed to have already returned home, said Amine ­Ghali, a political analyst.

“This is a serious security threat to the state, and how to deal with it is a major challenge for us,” he said.

Islamic State claimed the attack last Friday at the beach resort of Sousse, as well as an assault in March on the Bardo museum in Tunis that left 22 people dead.

After the museum attack, the government pushed legislation in parliament aimed at weakening terrorists and better protecting security forces. One of the proposals, a counterterrorism bill, would revise the law to allow suspects to be held for 15 days without being charged — instead of six — and with no access to a lawyer or judge. Another bill seeks to crack down on people who divulge national security secrets and would allow police more latitude in using lethal force.

The government says the new measures are necessary to maintain security in this nation of 11 million.

“When someone comes to kill you, and kill those around you, you have a state of legitimate defense,” President Beji Caid Essebsi said in an interview with the French newspaper Le Monde in April.

He said that government agencies “respect freedom,” and he emphasized that Tunisia was not about to fall “into a police state.”

Parliament President Mohamed Ennaceur said Monday that he would seek to pass the counterterrorism bill before July 25. “We will be after the government to take the necessary measures in all areas to fight against terrorism,” he said, according to the AP.

But human rights groups and democracy activists say that the proposals could undermine free speech and give too much power to the police, who in the past were notoriously brutal and unaccountable to the public.

One bill establishes the vaguely defined offense of “denigrating” the armed forces, a crime that would be punishable in some cases by prison time.

“These laws would give impunity to the police, who wouldn’t use the new powers to fight terror,” said Henda Chennaoui, a writer and human rights activist. “The powers would be used to restrict our political freedoms and crack down on civil society.”

Dismantling a police state

After the 2011 revolution, ­Tunisia’s authorities had to grapple with transforming what had been the security forces of a police state. The government has stepped up coordination with the United States on counterterrorism and received support from Britain in reforming the security services.

But progress has been slow, according to Tunisian analysts and politicians. The Interior Ministry, which oversees the ­police, is widely criticized as a complex and opaque institution.

Lotfi Azzouz, director of Amnesty International’s office in Tunisia, said that torture and other harsh tactics are still used frequently by police.

“The Interior Ministry is resisting reform and it has shown little interest in cooperating with civil society,” he said.

Bochra Belhaj Hamida, a parliamentarian from the governing Nidaa Tounes party, acknowledged problems with the Interior Ministry, which she described as an “unwieldy” institution.

But politicians are under public pressure to support tougher measures to combat security threats, she said.

“The problem is, public opinion is changing, and you have more people who say that having a police state is better than living in chaos,” she said. “Some people actually say they want a return of the police state.”

The staunchly secular Nidaa Tounes party won national elections last fall, in part because voters were unhappy with the previous Islamist government’s failures to prevent attacks by extremists on police, politicians and others.

Shadi Hamid, a Middle East analyst at the Brookings Institution, said the new government, led by people with ties to Ben Ali, the deposed leader, appears more interested in promoting stability than democratic reform.

“Nidaa Tounes came to power on a platform of promoting security, stability and competence, a platform where, if security takes precedence over human rights, then so be it,” he said.

The dilemma over how to balance national security needs and civil liberties has become familiar in the United States and other Western countries with the rise of al-Qaeda. But Tunisia has few examples in the Middle East to follow, said Walid Miaadi, 37, a resident of Tunis, the capital.

“In a sense, we’re alone in the region,” said Miaadi, a call-center worker. “If we followed our neighbors’ example and fought terrorism like they did, we wouldn’t be a democracy.”

Read more:

In birthplace of Arab Spring, Tunisia’s Islamists get sobering lesson in governing

Sousse: The beautiful Tunisian city that became a scene of terror

Three attacks deepen fears about Islamic State’s global reach

Today’s coverage from Post correspondents around the world