A Somali man who worked for Medecins Sans Frontieres shot dead a foreign aid worker employed by the aid agency and wounded another at the group's office in Somalia's capital Mogadishu on Thursday, an MSF official and the police said.

Police spokesman Abdullahi Barise said the gunman had been taken into custody. A Reuters witness said the man was dragged from the building, still holding a pistol.

The man was armed with a pistol and we understand he had a quarrel with the coordinator. It is very shocking, Barise said. He said the gunman had worked as a logistics officer for the agency.

The MSF official, who declined to be named, also said the Somali gunman had worked for the aid agency. An MSF nurse said the wounded aid worker had been taken to hospital.

MSF said in a statement: We confirm that a serious shooting incident has taken place in the MSF compound in Mogadishu. At this point we don't have more information about the scale and the extent of this incident. MSF is doing everything it can to ensure the security of its staff.

MSF, or Doctors Without Borders, operates in a number of locations in Somalia, providing emergency aid to people suffering from famine and the violence that has plagued the country for decades.

The attack happened in a bustling part of the capital which is under the control of government and African Union troops.

In mid-October, gunmen kidnapped two Spanish aid workers in Kenya, also working for MSF, with Kenyan police saying they suspected al Shabaab insurgents were responsible. Al Shabaab have said they were not responsible.

Somali government officials have since said the two were being held in the south of the country.

Last week, a gunman killed three Somali aid workers, including two with the U.N. World Food Programme (WFP), in the central Somali town of Matabaan, in a region under the control of the Ahlu Sunna militia group, which supports the Somali government.

Kenyan troops crossed into Somalia in October after a wave of kidnappings and cross-border raids it blamed on al Shabaab rebels.

Somalia descended into chaos in 1991 after dictator Mohamed Siad Barre was ousted and has not had a functional central government ever since.

(Writing by George Obulutsa)