Tunisian security forces have killed 28 militants after they launched a cross-border raid from Libya, the government says.
Fighting followed an attack on an army base and a police station in the eastern town of Ben Guerdane.
Seven civilians and nine members of the security forces were also killed in the clashes, according to the government.
There is concern in Tunisia about the threat from Islamist fighters based in Libya being able to cross the border.
President Mohamed Beji Caid Essebsi called the attack “unprecedented” and said it was an act of “savagery which came from our neighbour Libya”.
All entrances to the town have been shut and a dusk to dawn curfew has been imposed, the BBC’s Rana Jawad reports from the capital, Tunis.
The border crossing at Ras Jdeir has also been closed.
Last week, Tunisian forces killed five militants in the same area after they had entered Tunisia with the aim of carrying out “terrorist attacks”, Tunisia’s Prime Minister Habib Essid said on his Facebook page.
Analysis – Rana Jawad, BBC North Africa correspondent
Tunisia produces more people who go off to join jihadi groups in Iraq, Syria or Libya, than any other country in the region.
Now it is having to deal with the problem that officials have long been reluctant to admit to.
Tunisia is becoming increasingly vulnerable to militant attacks, but counter-terrorism measures by the state are not limited to securing its border crossing with Libya.
The army has been engaged in battles with local militants in the Chaambi Mountains, along its south-eastern border with Algeria for over a year.
Tunisian Islamist militants in Libya are now being targeted and may be trying to return to their home country to carry out attacks there.
Last year, two major attacks on popular tourist spots killed dozens of foreigners in the country.
In March, 22 people died when the Bardo Museum in Tunis was targeted, and in June, 38 people were killed when a gunman opened fire on tourists on the beach in Sousse.
The so-called Islamic State group, which now has a foothold in Libya, claimed responsibility for those attacks.
There was criticism at the time of Tunisia’s failure to deal with the militant threat.
The instability in Libya has allowed that threat to grow and Tunisia has responded by building a trench along the border to try and stop fighters infiltrating.