Police officers appear to move a dead body outside the French embassy. Photo Sky News
A gunman has killed four people during a shooting rampage in the diplomatic quarter of Tanzania largest city, Dar es Salaam.
Three police officers and a private security guard were fatally shot in the attack on Wednesday.
The assailant was later shot dead while holed up in a guardhouse at the French embassy's gate.
Inspector-General of Police Simon Sirro said the motive is not yet known but suggested the attack could be related to Tanzania's role in fighting Islamists in Mozambique.
Tanzanian troops were sent to the neighbouring country earlier this month to combat the insurgency as part of a regional security force.
Mr Sirro said in an interview aired on local television: "There are problems, our soldiers are there."
He also said police are working to identify the Dar es Salaam attacker.
Videos of the shooting have been shared online with footage showing the gunman inside the guardhouse - apparently filmed by onlookers from buildings across the street from the French embassy.
He exchanged fire at very close range with police and men who appeared to be embassy guards.
Police said the attacker had first shot two police officers with a pistol at an intersection in the district, which houses a number of diplomatic missions.
He took rifles from the fallen police officers, and headed on foot to the French embassy a few hundred metres away, firing randomly and occupying the guardhouse.
President Samia Suluhu Hassan said on Twitter that the attacker had been "neutralised" and "calm has returned".
"I send my condolences to the police service and the families of three policemen, and one officer of the SGA security company, who lost their lives after an armed person attacked them in the Salenda area of Dar es Salaam," Ms Hassan said.
Six people were injured in addition to the four who were killed, police commissioner of operations and training, Liberatus Sabas, said in a tweet shared by the account of the Tanzanian police force.
Mr Sabas told reporters it was too early to say whether the gunman was a Tanzanian national, or whether he had links to terrorism.
Tanzanian television aired footage showing police officers in bulletproof vests who appeared to be wrapping a dead body outside the embassy in white material to remove it from the scene.
SGA Security, which describes itself as a major security services provider in East Africa, did not immediately respond to requests for comment.
Earlier this year, Sky News was the first international broadcaster to reach the centre of the Mozambican town of Palma since it was ransacked by ISIS Mozambique, also known locally as al Shabaab. - Rebecca Speare-Cole, Sky News