Gunmen in military uniforms attacked a museum in downtown Tunis around noon on Wednesday, killing 19 people, officials said. Security forces later advanced into the museum and killed two gunmen in a firefight, state television reported.

Prime Minister Habib Essid said at a news conference that the dead included 17 foreigners and two Tunisians. Polish, Italian, Spanish and German tourists were among the dead, Mr. Essid said.

Eight people were killed as they got off a bus to visit the museum, according to an Interior Ministry spokesman; 10 more were taken hostage and then killed. State television reported that a Tunisian museum guard who was injured in the attack and died later of his wounds.

Local media reports said that it was possible a third gunman was involved and was still at large, and that there were possibly other accomplices as well. Tunisian authorities said at midafternoon that the operation to retake the museum was continuing and was nearly complete.

The attack began at a time when hundreds of visitors were on their way into the museum. Interior ministry officials said the gunmen were armed with grenades and assault rifles. Gunfire was first heard around 12:30 p.m.

Helicopters buzzed over the area in the afternoon, and Tunisian state television said they were evacuating people from the area, possibly including those injured in the attack.

The site of the attack, the National Bardo Museum, is in central Tunis near the national Parliament, which was evacuated as police officers responded to the attack and surrounded the area.

The identity and motivation of the attackers were not immediately clear. No group had claimed responsibility for the attack by early evening. An Interior Ministry spokesman said that the gunmen had probably been Tunisians, but their nationality had not been confirmed.

Tunisian officials said it was possible that the Parliament, rather than the museum, was the original intended target of the attack; some reports said that legislators were discussing an antiterrorism law on Wednesday.

Many Italians were in the area when the attack took place, the Italian foreign ministry said. A large cruise ship, the Costa Fascinosa, was docked in Tunis on Wednesday morning, and a number of its 3,100 passengers had gone ashore planning to visit the museum, a spokesman for the cruise line said. Piero Fassino, the mayor of Turin, Italy, told Italian television that six City Hall workers were there, but that only two had been heard from. “We are waiting for news with a certain anguish,” he said.

Tunisia was the country where the Arab Spring revolts against autocratic rule began four years ago.

As the assault on the museum unfolded on Wednesday, supporters of the Islamic State circulated the video again on social media, celebrating the attack as a fulfillment of that warning.

1000