Gunmen killed two Somalis and wounded a Swedish woman in central Mogadishu on Wednesday when they opened fire on their car in the latest attack in the troubled city, police said.

"A security guard and a driver was killed and a female foreigner has been injured after gunmen attacked them," said police official Abdi Mohamed.

The woman was reportedly travelling to visit a university when the attack took place around the K4 roundabout, a busy intersection in the heart of Mogadishu, Mohamed added.

"A Swedish woman was shot in Mogadishu and she is now at an African Union field hospital in Mogadishu. She has been in contact with our ambassador in Nairobi to prepare her medical transfer to Nairobi," Swedish foreign ministry spokeswoman Lena Tranberg said.

Witnesses said the gunmen were in a car and tried to block the vehicle carrying the woman and her guards.

"The gunmen, who drove a car, opened fire on the car with the white lady inside...one of her security guards was killed and a driver...then they fled after the shooting," said Shamso Ismail, a witness.

War-ravaged Mogadishu is one of the most dangerous cities in the world, despite the pulling out of fixed positions by Al-Qaeda linked Shebab fighters two years ago.

Foreigners usually travel in Mogadishu in armoured vehicles or with armed escorts.

"The white woman was bleeding, they rushed her to hospital, and then the police came and cordoned off the area," said Muktar Nure, another witness.

No one has claimed responsibility for the attacks, but Shebab fighters have carried out a series of bombings, attacks and killings aimed to overthrow the internationally-backed government.

Despite recent fighting in the ranks of the Shebab and the loss of a series of towns they held to a 17,700-strong African union force, analysts warn that the extremist group is far from defeated.

In June, Shebab suicide commandos carried out a brazen daylight attack on a fortified United Nations compound, while last month a suicide car bomber attacked a Turkish embassy complex in the city.