TUNIS (Reuters) - 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 53 people, including civilians, the government and residents said.

File photo of Tunisian soldiers standing guard at the border crossing at Ras Jdir Ben Guerdane, in this picture taken December 5, 2014. REUTERS/Stringer/Files

Local television broadcast images of soldiers and police crouched in doorways and on rooftops as gunshots echoed in the center 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.”

It was not clear if the attackers crossed the border, and no group immediately claimed responsibility. But it was the type of militant operation Tunisia’s government has feared as it prepares for potential spillover from Libya, where Islamic State 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 across the border. Militants trained in jihadist camps in Libya carried out two attacks last year in Tunisia.

“This attack was an unprecedented, well-organized. They wanted to try to control the Ben Guerdan region and name it as their new Wilaya,” President Beji Caid Essebsi said, referring to the name Islamic State uses for regions it considers part of its self-described caliphate.

Slideshow ( 5 images )

Soldiers killed 35 militants and arrested six, the Interior Ministry said. Hospital and security sources said at least seven civilians were killed along with 11 soldiers.

Troops also later discovered a large cache of rifles, explosives and rocket-propelled grenades in Ben Guerdan, a security source said.

“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.

REGIONAL JIHADISTS

More than 3,000 Tunisians have gone to fight with Islamic State 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. Islamic State has grown in the turmoil, taking over the city of Sirte and drawing foreign recruits.

Tunisian jihadists are taking a lead role in Islamic State camps in Libya, Tunisian security sources say.

Tunisian forces have been on alert for possible militant infiltrations since last month, when a U.S. air strike targeted mostly Tunisian Islamic State 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 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.