Dozens of Islamist fighters stormed through the Tunisian town of Ben Guerdan near the Libyan border on Monday attacking army and police posts in a raid that killed at least 50 people, including civilians, the government and residents said.
Local television broadcast images of soldiers and police crouched in doorways and on rooftops as gunshots echoed in the centre of the town. Bodies of dead militants lay in the streets near the military barracks after the army regained control.
Authorities sealed off the nearby beach resort town of Djerba, a popular destination for foreign and local tourists, imposed a curfew on Ben Guerdan and closed two border crossings with Libya after the attack.
"I saw a lot of militants at dawn, they were running with their Kalashnikovs," Hussein, a resident, told Reuters by telephone. "They said they were Islamic State and they came to target the army and the police."
'They said they were Islamic State and they came to target the army and the police'
It was not clear if the attackers crossed over the border, but it was the type of militant operation Tunisia's government had feared as it prepares for potential spillover from Libya, where Islamic State (IS) militants have gained ground.
Since its 2011 revolt to oust ruler Zine El-Abidine Ben Ali, Tunisia has struggled with Islamist militancy at home and over the border. Militants trained in jihadist camps in Libya carried out two attacks last year in Tunisia.
"This was an unprecedented, well-organised attack," President Beji Caid Essebsi told local radio. "But the people in the south can be confident the army and police will win against this barbarity across the border."
Soldiers killed 33 militants and arrested six, the Interior Ministry said. Hospital and security sources said at least seven civilians were killed along with ten soldiers.
"If the army had not been ready, the terrorists would have been able to raise their flag over Ben Guerdan and gotten a symbolic victory," said Abd Elhamid Jelassi, vice president of the Islamist party Ennahda, part of the government coalition.
A Tunisian soldier stands on a sandbank during a presentation of the anti-jihadi trench, near Ben Guerdan, eastern Tunisia, close to the border with Libya, on February 6. (Photo by Mohamed Messara/EPA)
More than 3,000 Tunisians have left to fight with IS and other groups in Syria and Iraq. Tunisian security officials say increasingly they are returning to join the militant group in Libya.
Since the fall of Muammar Gaddafi five years ago, Libya has slipped into chaos, with two rival governments and armed factions struggling for control. IS has grown in the turmoil, taking over Sirte city and drawing foreign recruits.
Tunisian jihadists are taking a lead role in IS camps in Libya, Tunisian security sources say.
Tunisian forces have been on alert for possible militant infiltrations since last month when a US air strike targeted mostly Tunisian IS militants at a camp near the border in Libya's Sabratha.
Western military advisers are starting to train Tunisian border forces to help better protect the frontier with electronic surveillance and drones and authorities have built a trench and barrier to help stop militants crossing.
Islamist militant gunmen trained in Libyan jihadist camps carried out two of the three major attacks on Tunisia last year, including assaults on the Tunis Bardo museum and a Sousse beach hotel targeting foreign tourists.
Follow VICE News on Twitter: @vicenews