At least 14 Tunisian troops were killed when gunmen attacked checkpoints in the remote Chaambi mountains, the deadliest militant strike on the North African country's armed forces.
Since April, thousands of Tunisian soldiers have been deployed to the Chaambi range bordering Algeria in an operation to flush out al-Qaida-linked militants seeking refuge there, some since fleeing French intervention in Mali last year.
During the attack on Wednesday night, militants with rocket-propelled grenades and rifles ambushed checkpoints the military had set up to try to control the Chaambi region.
The gunmen attacked as the soldiers were breaking their fast for the evening during the Muslim holy month of Ramadan, the Defense Ministry said. More than 20 soldiers were wounded.
Tunisia has struggled with the rise of radical Islamist militants since the 2011 popular revolt ended the rule of autocrat Zine el-Abidine Ben Ali and began its fragile steps towards democracy.
al-Qaida in the Islamic Maghreb, al-Qaida's North Africa branch, has claimed attacks in Tunisia in the past, but another militant group, Ansar al Sharia, which is listed as a terrorist organization by Washington, has also been blamed.
The mountain range is tough terrain with access into Algeria. Tunisian forces conducted several raids there and have bombarded caves after eight soldiers were captured and killed last year.
Algeria's military, experienced in battling its own Islamist militancy, have been coordinating on their side of the frontier, especially with sharing intelligence. But despite their large presence, Tunisian troops have been harried by improvised landmines and the porous border complicates tracking militants who use the area as a training ground.
One of the Arab world's most secular states, Tunisia has taken steps towards democracy since the 2011 revolt. It adopted a new constitution and allowed a caretaker government to take over until elections this year as a way to ease tensions between a leading Islamist party and secular opponents.
But hardline ultra-conservative Islamists are still influential, and Tunisia is one of the main sources of jihadist fighters traveling from North Africa to fight with Islamist groups in Syria and Iraq.
Last year a Tunisian man who had traveled to fight in Syria returned to carry out a suicide attack on a beach resort near the capital, killing only himself, but shocking a country that relies heavily on foreign tourism for revenue.
Tunisian officials also worry about arms and fighters spilling over from neighboring Libya, where the weak government is unable to impose order on brigades of former rebels and militias still fighting since the 2011 fall of Muammar Gaddafi.