African Union troops fought off an ambush waged by at least eight gunmen at a base in Somalia on Thursday, during an attack carried out by al Shabaab militants that was reportedly targeting a Christmas party at the compound.

The deadly clash left at least five militants dead and lasted for several hours, after an unverified number of fighters from al Shabaab infiltrated the AU mission (Amisom) base, which is located just outside of the international airport in Mogadishu. While the offensive was underway, al-Shabaab confirmed it was behind the attack.

"Our fighters have entered AU's Halane base by force through the gate and now fighting is going on inside the base," the Islamist militant group's spokesman Shiekh Abdiasis Abu Musab said at the time, the BBC reported.

After the fighting, Amisom said that its troops had managed to secure the compound and regain control, killing some of the militants involved. The mission confirmed on Twitter that the base was safe and under full control.

AMISOM base is safe & under control. The AMISOM soldiers are commended for their gallant effort in controlling the situation.— AMISOM (@amisomsomalia)December 25, 2014

Reports of casualties from the clash are varied. An Amisom spokesman told the Associated Press that five militants were killed.

"Our forces shot dead three of them, two detonated themselves near a fuel depot, and the three are believed to have escaped," Colonel Ali Aden Houmed said. "An investigation is underway on how they entered the base."

Without providing more information, the spokesman indicated some AU soldiers might have been killed during the attack. Other reports claimed at least four people were injured — three soldiers and one civilian.

More than 20,000 AU troops operate within Somalia, largely to thwart the US designated terrorist groups' activities. Amisom has boosted its offensive in recent years, succeeding in pushing al Shabaab out of some of its territory, weakening the hold it once had on Mogadishu and surrounding areas. Amisom's Mogadishu base is also home to the British and Italian embassies, as well as United Nations offices.