(CNN) -- A radical Islamist leader in Somalia said Sunday that a suicide attack that killed 21 African Union peacekeepers was the right thing to do.

A relative walks past caskets containing the bodies of Burundian soldiers.

Sheikh Hassan Dahir Aweys said Thursday's attack was meant to defend Islam.

"The Islamic religion permits such kinds of attacks if they are against known enemies and in the defense of the religion, but there are people who distort that explanation," Aweys said, addressing hundreds of people during a religious sermon at Elashabiyaha, a suburb of Mogadishu.

Suicide bombers, disguised in two U.N.-marked vehicles, rammed through the security gate of the mission's headquarters, which is attached to Mogadishu's airport.

They detonated explosives just as Somalia's transitional government and mission representatives concluded a high-level meeting inside the compound, said Nicolas Bwakira, the African Union's special representative for Somalia.

The attack killed four Somali civilians and 17 Ugandan and Burundian soldiers, including the mission's second-in-command, Burundian Maj. Gen. Juvenal Niyonguruza, he said.

The force commander, Ugandan Maj. Gen. Nathan Mugisha, was among the 40 wounded. He assumed command of the African Union Mission in Somalia -- known as AMISOM -- last month.

Al-Shabaab, the Islamist militia with ties to al Qaeda, claimed responsibility for the attack, according to the African Union.

The strike happened days after U.S. special forces targeted and killed a senior al Qaeda operative in southern Somalia.

Analysts hailed the death of Saleh Ali Saleh Nabhan as a major blow to al Qaeda's efforts to work with Al-Shabaab to try to gain a foothold in the lawless country.

Aweys, a rival of current Somali president Sheikh Sharif Sheikh Ahmed, condemned the killing of Nabhan.

"The U.S. government is responsible for all problems on the Muslim nation particularly on the Somalis," he said. Aweys heads the Hizbul Islam (Party of Islam) armed group which is allied with Al-Shabaab and opposes the presence of Ethiopian forces in Somalia.

The African Union has a 3,400-member peacekeeping force in Somalia, made up of troops from Burundi and Uganda. It operates under a U.N. mandate to support Somalia's transitional federal government.

The peacekeeping force is charged with protecting key government and strategic installations in Mogadishu, including the port, airport and presidential palace. It is the de facto military force of the weak, transitional Somali government.

Journalist Mohamed Amiin Adow contributed to this report.

All About African Union • Al Shabaab • Somalia • Al Qaeda