Somalis gather near one of the two car bombs used in the attack on the presidential compound in Mogadishu. The president was unharmed, but two government officials were killed.

Photo: Farah Abdi Warsameh, Associated Press

Somalis gather near one of the two car bombs used in the attack on...

Image 2 of 2

ATTENTION EDITORS - VISUAL COVERAGE OF SCENES OF INJURY OR DEATH
People look at bodies of suspected al Shabaab attackers, after Somali soldiers took the bodies and left them outside the gate of the Presidential Palace, the scene of a suicide attack, in Mogadishu February 21, 2014. Al Qaeda-linked militants al Shabaab attacked the Somali presidential palace compound on Friday, blasting through a gate with a car bomb and engaging in a fierce gun battle with African peacekeepers, police said. Somali president Hassan Sheikh Mohamud was not harmed in the assault on the heavily fortified compound, known as Villa Somalia. REUTERS/Feisal Omar (SOMALIA - Tags: CIVIL UNREST POLITICS) TEMPLATE OUT

Nine al-Shabab militants wearing military fatigues and carrying guns and grenades died after attacking the presidential palace with two car bombs on Friday, in an assault the president called a "media spectacular" by a "dying animal."

President Hassan Sheikh Mohamud was unharmed, but two government officials were killed, the interior ministry said.

The attack underscores a worrying new trend in Mogadishu: that despite a period of relative calm following al-Shabab's ouster from Mogadishu in August 2011, militants have carried out a series of deadly assaults in recent weeks that have seen the city hit with mortar fire and pitched battles.

Weapons meant for the Somali army could have been used by the militants in Friday's attack. A confidential U.N. Monitoring Group on Somalia and Eritrea reported this month that the country's military is selling weaponry in markets where the al Qaeda-linked militants buy weapons.

In at least one case weapons were sold by a military commander directly to an al-Shabab commander, the confidential report said.

Friday's attack against the compound where the president and prime minister live began with a car bomb explosion, followed by an assault by gunmen on palace guards, said police Capt. Mohamed Hussein. Al-Shabab, an al Qaeda-linked group, claimed responsibility.

"President just called me to say he's unharmed. Attack on Villa #Somalia had failed. Sadly some lives lost. I condemn strongly this terrorism," the U.N. representative to Somalia, Nick Kay, said on Twitter. He added later: "The Somali people are tired of shootings, bombings and killings. It's time for a new chapter in Somalia's history."

The two others killed included a former intelligence commander and an aide to the prime minister, a Somali American named Mohamud Hersi Abdulle, said Hussein.

"Apart from media headlines, #Shabaab will achieve nothing from it," a Twitter account run by the office of Hassan Sheikh Mohamud said. "Don't be fooled by this 'media spectacular.' This is another act of desperation from a dying animal."

Al-Shabab has been waging war in Somalia for years as it tries to oust a Western-backed government. Weakened from its apex of power, the militants are still able to launch vicious attacks.