Eight gunmen infiltrated the main African Union (AU) base in Mogadishu on Thursday and killed three peacekeepers and a civilian contractor, the AU mission in Somalia said.
Somali militant group al Shabaab claimed responsibility for the attack, which lasted several hours, and said it had killed 14 peacekeepers.
Witnesses reported hearing bomb blasts and volleys of gunfire throughout the day.
"We targeted the enemies at a time they were celebrating Christmas,” Sheikh Abdiasis Abu Musab, al Shabaab’s military operations spokesman, told Reuters.
In the past, al Shabaab has exaggerated the number of soldiers it has killed, while officials have played down losses.
The al Qaeda-aligned militants want to topple the Western-backed Mogadishu government and describe AU troops as "Christian enemies.”
The group also wants to impose its own strict version of sharia law in the country.
The raid showed al Shabaab’s ability to carry out high-profile attacks in the capital even as it is losing territory in rural areas to AU peacekeepers who have launched two major offensives this year.
"The terrorists, some of whom were disguised in Somali National Army uniforms, breached the base camp around lunch hour and attempted to gain access to critical infrastructure, during which five of them were killed and three others captured,” the AU peacekeeping mission in Somalia, AMISOM, said in a statement.
It did not disclose the nationalities of the peacekeepers and civilian contractor killed in the attack.