The brazen daylight assault sparked panic at the nearby parliament and the National Bardo Museum itself, a magnet for the tourists who contribute so much to the economy.
The gunmen, dressed in military uniforms, opened fire on the tourists as they got off a bus then chased them inside the museum, said Prime Minister Habib Essid.
Among the dead were five Japanese, four Italians, a Colombian mother and child and one each from Australia, France, Poland and Spain, Essid announced on television in what he said was a definitive toll.
The nationality of a 16th victim was not given, while the identity of the final fatality had not yet been established.
Two British people were "caught up" in the attack, a spokesman for London's foreign ministry said, but did not clarify whether the two had been hurt.
"We can confirm that two British nationals were caught up in the shootings in Tunis on Wednesday and that we are providing consular assistance," the Foreign Office spokesman said.
Police killed two gunmen and the authorities were still hunting for possible accomplices, said the prime minister.
A Tunisian bus driver and a policeman were also reported dead in the attack on the Bardo, famed for its collection of ancient artefacts.
President Beij Caid Essebsi, who visited some of the dozens being treated for wounds in a Tunis hospital, denounced the "horrible crime".
"I want the Tunisian people to understand that we are in a war against terrorism and that these savage minorities do not frighten us," he said.
"We will fight them without mercy to our last breath."
The government announced 42 people were wounded, with Health Minister Said Aidi saying they included citizens of France, South Africa, Poland, Italy and Japan.
The attack appeared to be the worst on foreigners in Tunisia since an Al-Qaeda suicide bombing of a synagogue killed 14 Germans, two French and five Tunisians on the island of Djerba in 2002.
It sparked outrage, with hundreds of people gathering later in a major thoroughfare of the capital, singing the national anthem and shouting slogans against what they called terrorists.
It also drew strong condemnation from world leaders.
President Francois Hollande expressed French "solidarity" with Tunisia and US Secretary of State John Kerry denounced the "wanton violence".
UN Secretary General Ban Ki-moon condemned what he called the "deplorable" attack.
The UN Security Council also slammed what it called "this heinous act."
Ban "condemns in the strongest terms today’s attack" against the Bardo Museum and "conveys his deepest condolences to the families of the victims of this deplorable act," said his deputy spokesman Farhan Haq.
British Prime Minister David Cameron condemned the attack, writing on Twitter "Appalled by sickening terrorist attack in Tunis - my thoughts are with those affected. UK stands ready to support Tunisia."
Some officials said hostages had been taken at the museum but this was not confirmed.
There was no claim of responsibility, but Tunisia has struggled to tackle a rise in attacks from Islamist extremists.
Interior ministry spokesman Mohamed Ali Aroui told reporters "two or more terrorists armed with Kalashnikovs" had targeted the museum, where about 100 tourists had been inside.
"Anti-terrorist units" had entered the museum and, about four hours after the incident began, declared that "the operation is over".
Essid said "there is a possibility, but it is not certain, that (the two gunmen) could have been helped. We are currently conducting extensive search operations to identify the two or three terrorists who possibly participated in the operation."
Signup to our newsletter and follow us on Facebook and Twitter!
Museum employee Dhouha Belhaj Alaya said she heard "intense gunfire" around noon.
"My co-workers were screaming 'Run! Run! Shots are being fired!'" she told AFP. "We escaped out the back door with co-workers and some tourists."
French tourist Fabienne recounted how she and others hid in one of the museum's galleries along with their guide.
"We couldn't see anything, but there must have been a lot of them. We were afraid that, at any moment, they would come kill us," she told France's BFM television.
Work was suspended at parliament during the attack.
Islamist lawmaker Monia Brahim said gunfire from the initial assault prompted committees to suspend their meetings as colleagues were ordered to assemble in the main chamber.
"There was enormous panic," another lawmaker, Sayida Ounissi, wrote on Twitter, saying hearings on Tunisia's anti-terrorism law were taking place at the time.
At least four French citizens were among the wounded, a diplomatic source said.
Italy said at least two of its citizens had been wounded and police took about 100 to safety.
A cruise ship carrying more than 3,100 passengers, the Costa Fascinosa, was docked in Tunis at the time, and some had gone ashore planning to visit the museum, the cruise line said.
A statement did not specify if any passengers were inside the museum at the time of the attack.
But it said the ship's departure was likely to be delayed and that a support team was headed from Genoa.
Tunisia has seen an upsurge in Islamist extremism since the 2011 revolution that ousted longtime strongman Zine El Abidine Ben Ali.
Dozens of police and military personnel have been killed or wounded in attacks blamed on Islamist militants.
An army offensive against the jihadists, who are linked to Al-Qaeda in the Islamic Maghreb, has been under way since 2012 but the ground and air campaign has failed to eliminate them.
The country is also fighting against the radicalisation of Muslim youth. Authorities say as many as 3,000 Tunisians have gone to Iraq, Syria and neighbouring Libya to fight in jihadist ranks, including with the Islamic State group.
Some 500 jihadists are believed to have since returned home.
Essebsi said the "top priority" for the government, which took office last month after Tunisia's first free elections, is "providing security and the battle against terrorism".
Tunisia kicked off the Arab Spring and has taken pride in forming a stable and democratic government.
It is hoping to rebuild its once-burgeoning tourism industry, which is struggling to recover from the effects of the revolution.
Tourist arrivals dropped by three percent last year.
Mohzen Marzouk, a presidential adviser, said Wednesday's attack "targeted our economy".
"But we cannot let this blow affect us. And I'm sure the world will keep its confidence in us," he said.