Tunisian security forces pressed a search for militants near the Libyan border on Tuesday after a deadly raid the authorities described as an unprecedented assault by the Islamic State (IS) group.
Analysts said Monday's attacks show that militants are keen to spread their influence from Libya to Tunisia and to set up a new stronghold in the country.
Prime Minister Habib Essid said about 50 extremists were believed to have taken part in the coordinated dawn attacks on an army barracks and police and National Guard posts in the border town of Ben Guerdane.
He said 36 attackers were killed and seven captured in a fierce firefight that also saw the deaths of seven civilians and 12 security force personnel.
Essid said the militants "murdered one internal security force member in his own home" and that three civilians and 14 security personnel were also wounded.
"The (security forces') reaction was rapid and strong. We won a battle and are prepared for any others," he said.
"Now they know Tunisia is no easy pushover and that it is not so simple to set up an emirate in Ben Guerdane."
On Monday, Essid said that the operation's aim had been to create a "Daesh (IS group) emirate" in the town.
Michael Ayari, an analyst with the International Crisis Group, agreed, saying the attacks were an "extension of the armed conflict so far confined to Libya".
Some IS group militants "consider that Ben Guerdane could become a strategic 'liberated' zone that would include southeastern Tunisia and the Tripoli region," he said.
Interior ministry spokesman Yasser Mesbah said the search for any militants still at large was continuing in the border area.
He said a nighttime curfew imposed in the town after the attack had been well respected and that the situation was "stable".
However, witnesses spoke of sporadic gunfire during the day on Tuesday as police and soldiers flooded Ben Guerdane.
The walls of one building in which attackers had been holed up were riddled with bullet holes.
Essid called for vigilance and promised a full investigation.
"There are lessons to be learned from this terrorist attack. There will be a thorough assessment of what happened, and we will draw all the conclusions," he said.
"It may be that there was a failure at a certain level, that of intelligence, other elements."
Carnegie centre researcher Hamza Meddeb said the attacks could have been to avenge the killing of dozens of people last month in a US air strike on an IS group training camp near Sabratha, Libya.
Sabratha lies just 100 kilometres (62 miles) from Tunisia's border and several Tunisian militants were said to have been killed in the US raid.
"Some wounded militants had said (after the raid) that IS group would seek revenge by carrying out attacks in Tunisia," said Meddeb.
A US official has said one of those "likely killed" in the February air strike was Noureddine Chouchane, a senior IS group operative behind attacks in Tunisia.
On Monday, President Beji Caid Essebsi described the attack as "unprecedented" and was "maybe aimed at controlling" the border region, vowing to "exterminate these rats".
The United States and the European Union also condemned the attacks, with Washington offering to help Tunis confront militants.
Residents said the assailants appeared to be natives of the region.
They stopped people, checked their ID cards apparently to seek out members of the security forces, and announced their brief takeover of Ben Guerdane as "liberators".
On Tuesday the authorities said that "large quantities" of arms and ammunition had been recovered.
It was the second clash in the border area in less than a week as Tunisia battles to prevent the large number of its citizens who have joined IS group in Libya from returning to carry out attacks at home.
Two deadly IS group attacks on foreign tourists last year that have dealt a devastating blow to Tunisia's tourism industry are believed to have been planned from Libya.
Militants have taken advantage of a power vacuum in Libya since the NATO-backed overthrow of longtime dictator Moamer Kadhafi in 2011 to set up bases in several areas, including near Sabratha.
Tunisia has built a 200-kilometre (125-mile) barrier that stretches about half the length of its border with Libya in an attempt to stop militant incursions.