It prompted authorities to close the frontier and order a nighttime curfew.
Prime Minister Habib Essid, using an Arabic acronym for the Islamic State (IS) group, said the operation's aim had been to create a "Daesh emirate" in Ben Guerdane, but the army and internal security forces had thwarted the attackers.
Essebsi, in an earlier statement broadcast on state television, said the assault was "maybe aimed at controlling" the border region with Libya, and vowed to "exterminate these rats".
State Department spokesman John Kirby condemned the "cowardly attack" and offered fresh US help to Tunis, while EU foreign policy chief Federica Mogherini said the attack "once more demonstrates the gravity of the threat faced by Tunisia".
Residents told AFP the assailants appeared to be natives of the region.
They stopped people, checked their IDs apparently to seek out members of the security forces, and announced their brief takeover of Ben Guerdane town as "liberators".
"I was about to open my shop, at 5:30 (am), when I heard gunshots coming from not far from here," said a grocer near the hospital, asking not to be identified.
When he went to see what was happening, he saw two jihadists drive off with an ambulance, an account confirmed by a medic.
Other jihadists pointed a gun at him, told him to kneel down and asked for his identity papers, which in Tunisia show your profession.
- 'Kill him' -
"I told him I didn't have my ID on me. His comrade said: 'Kill him.' But instead he shouted: 'We are Al-Imara al-Islamiya (the Islamic emirate). We've come to liberate you.'"
The assailants, apparently working from a hit list, murdered an anti-terrorist brigade official at his home, friends said.
"They knew him! They knew him!" insisted the man's uncle, Mustapha Abdelkebir, a civil activist, amid tears of grief.
It was the second deadly 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 in Libya from returning to carry out attacks at home.
Jihadists 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 Sabratha between Tripoli and the Tunisian border.
The government in Tunis said an army barracks and police and National Guard posts in Ben Guerdane were attacked in coordinated pre-dawn assaults.
The defence and interior ministries said at least 36 jihadists, six members of the National Guard, two policemen, a customs official and a soldier died in the fighting. Seven civilians were also killed.
Seven militants were captured, the defence ministry said.
A medic said a 12-year-old boy was among the dead.
An AFP correspondent reported that schools and offices were closed and troops were posted on rooftops as helicopters patrolled overhead.
Residents were urged to stay indoors even before the 7:00 pm (1800 GMT) nighttime curfew began.
- Jihadist presence growing -
As well as closing border crossings with Libya, authorities also closed the main road north to the rest of Tunisia, the correspondent said.
Authorities said ground and air patrols along the border would be reinforced.
Last Wednesday, troops killed five militants in a firefight outside the town in which a civilian was also killed and a commander wounded.
Troops have been on alert in the area following reports of militants infiltrating since a US air strike on an IS training camp in Libya on February 18 killed dozens of Tunisian militants.
Deadly IS attacks on foreign holidaymakers last year, which dealt a devastating blow to Tunisia's tourism industry, are believed to have been planned from Libya.
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.
- US air strike -
The American strike on the IS training camp outside Sabratha targeted the suspected mastermind of two of last year's attacks, Noureddine Chouchane.
Washington has said Chouchane was likely among the dozens of militants killed, and that the raid probably averted a mass shooting or similar attack in Tunisia.
According to a UN working group, more than 5,000 Tunisians have travelled abroad to join jihadist groups, many to Libya.
Western governments have been increasingly alarmed by the growing IS presence in Libya just 300 kilometres (185 miles) across the Mediterranean from Europe, and have made contingency plans for intensified military action.
Rival administrations jostling for power since mid-2014 in Libya are being urged to sign up to a UN-brokered national unity government to facilitate the fight against the jihadists.
-------------------------------------------------------------------------------
Prime Minister Habib Essid, using an Arabic acronym for the Islamic State (IS) group, said the operation's aim had been to create a "Daesh emirate" in Ben Guerdane, but the army and internal security forces had thwarted the attackers.
Essebsi, in an earlier statement broadcast on state television, said the assault was "maybe aimed at controlling" the border region with Libya, and vowed to "exterminate these rats".
State Department spokesman John Kirby condemned the "cowardly attack" and offered fresh US help to Tunis, while EU foreign policy chief Federica Mogherini said the attack "once more demonstrates the gravity of the threat faced by Tunisia".
Residents told AFP the assailants appeared to be natives of the region.
They stopped people, checked their IDs apparently to seek out members of the security forces, and announced their brief takeover of Ben Guerdane town as "liberators".
"I was about to open my shop, at 5:30 (am), when I heard gunshots coming from not far from here," said a grocer near the hospital, asking not to be identified.
When he went to see what was happening, he saw two jihadists drive off with an ambulance, an account confirmed by a medic.
Other jihadists pointed a gun at him, told him to kneel down and asked for his identity papers, which in Tunisia show your profession.
- 'Kill him' -
"I told him I didn't have my ID on me. His comrade said: 'Kill him.' But instead he shouted: 'We are Al-Imara al-Islamiya (the Islamic emirate). We've come to liberate you.'"
The assailants, apparently working from a hit list, murdered an anti-terrorist brigade official at his home, friends said.
"They knew him! They knew him!" insisted the man's uncle, Mustapha Abdelkebir, a civil activist, amid tears of grief.
It was the second deadly 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 in Libya from returning to carry out attacks at home.
Jihadists 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 Sabratha between Tripoli and the Tunisian border.
The government in Tunis said an army barracks and police and National Guard posts in Ben Guerdane were attacked in coordinated pre-dawn assaults.
The defence and interior ministries said at least 36 jihadists, six members of the National Guard, two policemen, a customs official and a soldier died in the fighting. Seven civilians were also killed.
Seven militants were captured, the defence ministry said.
A medic said a 12-year-old boy was among the dead.
An AFP correspondent reported that schools and offices were closed and troops were posted on rooftops as helicopters patrolled overhead.
Residents were urged to stay indoors even before the 7:00 pm (1800 GMT) nighttime curfew began.
- Jihadist presence growing -
As well as closing border crossings with Libya, authorities also closed the main road north to the rest of Tunisia, the correspondent said.
Authorities said ground and air patrols along the border would be reinforced.
Last Wednesday, troops killed five militants in a firefight outside the town in which a civilian was also killed and a commander wounded.
Troops have been on alert in the area following reports of militants infiltrating since a US air strike on an IS training camp in Libya on February 18 killed dozens of Tunisian militants.
Deadly IS attacks on foreign holidaymakers last year, which dealt a devastating blow to Tunisia's tourism industry, are believed to have been planned from Libya.
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.
- US air strike -
The American strike on the IS training camp outside Sabratha targeted the suspected mastermind of two of last year's attacks, Noureddine Chouchane.
Washington has said Chouchane was likely among the dozens of militants killed, and that the raid probably averted a mass shooting or similar attack in Tunisia.
According to a UN working group, more than 5,000 Tunisians have travelled abroad to join jihadist groups, many to Libya.
Western governments have been increasingly alarmed by the growing IS presence in Libya just 300 kilometres (185 miles) across the Mediterranean from Europe, and have made contingency plans for intensified military action.
Rival administrations jostling for power since mid-2014 in Libya are being urged to sign up to a UN-brokered national unity government to facilitate the fight against the jihadists.
-------------------------------------------------------------------------------