A Tunisian soldier opened fire on fellow troops at a military barracks in the capital Tunis, killing seven people before he was killed, a defence ministry spokesman said.
Belhassen Oueslati said 10 others were injured in the shooting, including one person who was in a serious condition.
He described the incident as an "isolated act, not a terrorist act" and said the motive will be determined by an investigation.
Police reinforcements were sent to the area after the shooting, combing nearby streets, while a helicopter circled overhead. The defence ministry said a nearby school was also evacuated.
Authorities sought to calm the public in a city where tensions remain high after an attack on the National Bardo Museum on March 18 that killed 22 people, mostly foreign tourists. The shooting at the Bouchoucha barracks was about a kilometre from the museum.
Mr Oueslati said the situation was under control by mid-morning.
He said the soldier had been forbidden from carrying a weapon after displaying "troubled behaviour due to family problems" and had seized another man's weapon for the attack.
Since overthrowing its secular dictator in 2011, Tunisia has been battling militant groups with links to Islamic State and al Qaida, which have carried out attacks on security forces.