Two attackers and at least two security guards, thought to be Kenyan nationals, and a Somali policeman were killed in the incident, while four others were wounded.
At least five people, including two of the attackers, were killed during a raid by armed militants on an army base near the Somali capital's international airport.
"Security Forces have shot dead two armed terrorists who attempted to force their way into the army base near #Mogadishu’s Adan Abdulle International Airport on Wednesday and police will give details shortly," state TV reported.
An internal diplomatic security memo seen by Reuters said two security guards, thought to be Kenyan nationals, and a Somali policeman were also killed in the incident, while four others were wounded.
Al Qaeda-linked Al Shabab said it was behind the attack, and had fired mortars into the camp, where African Union (AMISOM) peacekeeping troops, United Nations and other international organisations are based.
Abdiasis Abu Musab, an Al Shabab spokesperson, said the group's fighters had gained entry to the base and inflicted casualties, but he did not provide any evidence.
Videos and photos shared on social media showed black smoke billowing from an area near the airport runway.
Mahad Hirsi, a witness at the compound, told Reuters he saw the attackers force their way through the gate and start shooting, and that "a number of injured AMISOM soldiers (were) lying on the ground".
Spokespeople for AMISOM and the United Nations' Somalia office did not immediately respond to Reuters' calls and messages requesting comment.
A travel agent said flight traffic had been halted due to the gunfire near the airport.