Tunisia's parliament on Saturday overwhelmingly approved legislation allowing the death penalty for those convicted on terrorism charges after Islamist militant attacks that killed dozens of foreign visitors in the past few months.

Last month, a gunman killed 38 mostly British tourists in the Tunisian seaside city of Sousse. In March, two gunmen killed 21 foreign tourists and a policeman at Tunis' Bardo Museum.Both attacks were claimed by the Islamic State jihadist group.

MPs approved the bill by a margin of 174-0 with 10 abstentions early on Saturday after three days of debate in what parliament speaker Mohamed Ennaceur called an "extraordinary effort" to make the North African country a safer place.

Human Rights Watch had criticised the bill, which also eases arrests of suspects, saying it "would open the way top rosecuting political dissent as terrorism, give judges overly broad powers, and curtail lawyers' ability to provide an effective defence".

The bill, which had been debated in parliament for years but put forward after the Sousse attack, will replace a law from 2003 which then-president Zine al-Abidine Ben Ali, toppled in a popular uprising in 2011, had used to crush dissent.

The new "law against terrorism and money laundering" permits the death penalty for terrorism-related offences such as killings of foreign visitors or someone enjoying "international protection", a reference to diplomats.

Tunisia has undergone a largely peaceful transition to democracy since its 2011 popular uprising. But its army has been fighting a rise in Islamist militancy. Tunisia is especially concerned about militants entering from adjacent Libya, where Islamic State has established a toehold amid chaos caused by two rival governments battling for control, leaving a security vacuum.

Tunisia says it has started building a wall and trench along the insecure 168 km (105 miles) of its frontier with Libya. The Sousse gunman obtained training with militants in Libya beforecarrying out his attack.

On Thursday, security forces killed an Islamist militant and arrested 13 in a security operation in the northern state of Bizerte, the interior ministry said. Three more were arrested during raids on homes of suspected militants on Friday.