Mogadishu, Somalia (CNN) -- Militants carried out a deadly attack on Somalia's presidential palace Friday, officials and eyewitnesses said.
An explosion at the gate was followed by an exchange of gunfire between the fighters and security guards, police officer Abdi Mohamed said.
A U.N. representative said in a post on Twitter that President Hassan Sheikh Mohamud told him by phone that he was unharmed.
Terror network Al-Shabaab, al Qaeda's affiliate in Somalia, claimed responsibility for the attack.
Somalia's national security minister, Adbikarin Hussein Guled, said at least 12 people, seven of them Al-Shabaab attackers, were killed in the attack
Two government officials who died were named as the secretary to the Prime Minister and the former deputy national intelligence agency chief, Gen. Nur Shirbow.
Sheikh Abdiaziz Abu Musab, Al-Shabaab's military operations spokesman, said the group had achieved its objectives in the attack.
The attack comes just over a week after a car bombing near the airport in the Somali capital, Mogadishu, killed two people and wounded four more, according to police.
Al-Shabaab also claimed responsibility for that attack.
The group has been designated a terrorist organization by the United States. It hopes to turn Somalia into a fundamentalist Islamic state by force but has launched attacks in other countries, such as Kenya and Uganda, that have killed dozens.
Journalist Omar Nor reported from Mogadishu and Laura Smith-Spark wrote in London. CNN's Ben Brumfield and Saad Abedine contributed to this report.