The dead included 21 attackers, one Tunisian soldier and four civilians, the interior and defense ministries said in a joint statement.
A 12-year-old girl was among the civilians who were killed.
The gunmen targeted a police station and military facilities at dawn in the border town of Ben Guerdane in eastern Tunisia, Interior Ministry spokesman Yasser Mosbah told The Associated Press earlier.
Hospital official Abdelkrim Sakroud said on state radio that three corpses had been brought in, including that of the 12-year-old girl.
More From This Section
The violence comes amid increasing international concern about Islamic State extremists in Libya. Tunisia's fledgling democratic government is especially worried after dozens of tourists were killed in extremist attacks in Tunisia last year.
Last week, Tunisian security forces killed five heavily-armed men in an hours-long firefight after they crossed into the country from Libya with a larger group.
Tunisian security forces had been placed on alert based on "precise information" of possible border infiltrations following the February 19 US raid on an IS camp near the Libyan town of Sabratha, not far from the Tunisian border, the statement said.
Tunisia was targeted last year by three attacks that left 70 people dead and were claimed by IS. According to Tunisian authorities, the attackers had been trained in Libya.