Tanzania's president on Wednesday said five people are dead, including three police officers, after a gun battle with an armed man near the French Embassy in Dar es Salaam.
It was not immediately clear whether the shootout in the heavily guarded diplomatic area was a terror attack.
Liberatus Sabas, Tanzania's head of police operations, said the gunman attacked two police officers, took their guns and then "began shooting sporadically towards the French Embassy."
"He then took cover at a structure next to the French Embassy where he continued shooting," Sabas said.
Inspector general of police Simon Sirro told reporters the armed man was a foreigner and police believe he was from Somalia.
Sirro also warned the attack could be linked to the jihadist insurgency in neighbouring Mozambique, where a growing number of African nations are jointly pursuing the fighters.
The confrontation occurred shortly after President Samia Suluhu Hassan addressed security officials in another part of the city, Tanzania's commercial hub.
The president later said three police officers, a member of the auxiliary police and the armed man were killed, and she ordered an investigation.
The U.S. Embassy in a security alert warned citizens to avoid the area.
The shootout occurred not far from the scene of the deadly bombing in 1998 at the U.S. Embassy.