Men with assault rifles fired at tourists climbing from buses in front of the National Bardo Museum in central Tunis near the country's parliament, sending dozens sprinting for safety.
Two gunmen were killed, but Prime Minister Habib Essid said a manhunt was on for at two or three others.
The identity of the attackers was not clear.
Security forces immediately flooded the area, and Tunisia's parliament building, where deputies were debating the new anti-terrorism law, was evacuated.
More From This Section
Tunisia has been struggled to keep extremist violence at bay since the overthrow of its dictator in 2011, and the attack was the worst on a tourist site since an al-Qaeda car bomb killed 21 people, mostly Germans, in 2002.
"Our nation is in danger," Essid warned in an address on national television this evening after the siege ended.
"We will be merciless in the defense of our country," he added, describing the attack as an unprecedented assault on Tunisia's economy. He promised increased security in tourist zones and asked residents to be extra alert.
Several other people were reported wounded in the attack, including three Poles and at least two Italians. The Italian Foreign Ministry said 100 other Italians had been taken to a secure location.
Some of the Italians at the museum were believed to have been passengers aboard the Costa Fascinosa, a cruise liner that had docked in Tunis while on a seven-day tour of the western Mediterranean.
The attack was a strong blow to Tunisia's efforts to revive its crucial tourism industry.
The Bardo, built in a 15th century palace, is the largest museum in Tunisia and houses one of the world's largest collections of Roman mosaics among its 8,000 works.