Somalia's al-Shabab fighters have killed three African Union soldiers and a civilian after staging an attack on the force's heavily fortified headquarters in the capital Mogadishu.

The AU force, known as AMISOM, said troops regained control of the base in Mogadishu after Thursday's attack that left five of the assailants dead while three others were captured.

"Three AMISOM soldiers and a civilian contractor unfortunately lost their lives," AMISOM said in a statement, updating earlier information that said the four had been injured in the Christmas Day attack.

The statement did not mention the nationalities of the victims, but a contingent of Ugandan soldiers is in charge of the base. Burundi, Kenya, Ethiopia and Djibouti have also contributed troops to the mission.

AMISOM said some of the attackers were wearing Somali national army uniforms when they "breached the base camp around lunch hour and attempted to gain access to critical infrastructure".

"AMISOM has regained control of the Halane base camp and restored normalcy," the statement added.

Maman S Sidikou, head of AMISOM, speaks to Al Jazeera

Al-Shabab claimed responsibility for the attack almost as soon as the first shots rang out.

"Our fighters are inside the headquarters of the foreign troops in Somalia," Abdulaziz Abu Musab, the spokesman, told the AFP news agency earlier on Thursday, adding that several AU soldiers had been killed.

Maman S Sidikou, head of AMISOM, told Al Jazeera that the force would act "very quickly to the new tactics" being used by al-Shabab and take the measures required to prevent any such events happening again.

A Western security source said between 15 and 20 attackers were involved in the assault.

Paddy Ankunda, the Ugandan spokesman for AMISOM, told AFP the assailants "sneaked into the base camp near the airport... but our troops foiled the attack".

He added on Twitter that the "attackers sneaked in incognito".

Somali police official Abdi Ahmed said loud explosions had resonated at the rear entrance to the Halam base, where exchanges of gunfire were also heard.

The AU force headquarters is a fortified structure located on the grounds of the Mogadishu airport, which is also under high security.

The AMISOM force, deployed since 2007, currently has some 22,000 African Union troops.

They have managed to push al-Shabab out of the capital, but the fighters still hold large swathes of territory.