The shooting occurred as hundreds of people who had returned from camps for the displaced gathered at a police station in the Abdiaziz district, north Mogadishu, to wait for food, said a resident, who only gave her name as Maka.
"The people were just waiting when the police opened fire," she said. Three people were killed on the spot, among them a pregnant woman, and two others died later.
"There were no warning shots; they just shot at the people."
Abdi Haji Gobdon, a government spokesman, confirmed the incident and said it was regrettable and due to negligence. He said the matter was being investigated.
The UN World Food Programme (WFP) said it had heard about the shooting incident but knew nothing more about it. "The area was a planned food distribution site, but at the time of the incident there was no food and no WFP staff present," said Said Warsame, WFP-Somalia public information officer.
The agency diverted the distribution to another site, "once we learned of the incident", he added.
Most of those who had gathered at the police station had just returned to the area after fleeing the violence in February, according to a local journalist.
Aid workers estimate that at least 400,000 people have fled Mogadishu since February to seek shelter in other regions of the country. However, at least 117,000 of the displaced have since returned and need humanitarian assistance.
Meanwhile, violence in Mogadishu continues, despite a dusk-to-dawn curfew since 22 June.
"We had one of the biggest explosions today [26 June] and the heaviest face-to-face fighting, between insurgents and Ethiopian-backed government forces since April, last night [25 June]," a local journalist said.
He said the explosion near Bakara market killed six people, four of them women. There were no casualty figures for fighting on the night of 25 June since "no one could go out", because of the curfew.
More than a dozen explosions and attacks on government targets have been recorded since 22 June, he added.