Witnesses described scenes of panic and confusion after the shooting at a hotel in the district of Sousse, about 140 kilometres (87 miles) south of Tunis.
The toll from the attack is "27 dead including tourists," Interior Ministry spokesman Mohamed Ali Aroui said without giving their nationalities.
"It was a terrorist attack" against the Marhaba hotel, he said. "The assailant was killed."
The shooting comes just months after a March attack on the Bardo National Museum in Tunis killed 21 foreign tourists and a policeman.
