* President absent from compound when hit by al Shabaab
* Al Shabaab militants claim assault in Mogadishu
* Conflicting reports on whether fighting is over (Adds details of earlier fighting)
By Feisal Omar and Abdirahman Hussein
MOGADISHU, July 8 (Reuters) - Islamist militants attacked Somalia's presidential compound on Tuesday with a car bomb and gunmen broke through a perimeter wall but were repulsed by security forces, and the president was not there at the time, the interior ministry said.
Up to five members of the al Shabaab Islamist group, which claimed responsibility, were killed, Interior Minister Abdullahi Godah Barre told Reuters. Three militants were confirmed dead, and one or two more were believed to have died in the car blast.
The assault was the most dramatic in a string of attacks in the capital Mogadishu by al Shabaab since it launched a campaign during the current Muslim fasting month of Ramadan.
But President Hassan Sheikh Mohamud was not there at the time as he was at another location attending an iftar, the meal to break the Ramadan fast after sunset.
"I can assure you the president is not hurt and as a matter of fact he was not in the palace," the minister said, adding the gunmen were repulsed in the car park near the prime minister's offices and had not made it to the presidential quarters.
It was the second time since February that al Shabaab had attacked the sprawling compound, which includes the presidential buildings and other government offices. Officials said security had been tightened since then, including adding stronger gates.
Officials said the attackers were quickly defeated by Somali security forces and members of the African Union peacekeeping force, which remains the backbone for Somali state security.
However, al Shabaab said fighting still raged after officials said it was finished. "Let them enter the palace and meet us if the fighting is over," Sheikh Abdiasis Abu Musab, spokesman for al Shabaab's military operations, told Reuters.
He said their fighters had killed 14 soldiers in the raid, while the minister said there had been no such casualties. The minister also said details of the attack were still not clear and greater clarity would come in the morning.
Police said earlier there was also fighting near a cell holding al Shabaab militants. "I understand there is fighting going on around the underground cell where militants are jailed - just outside the palace," Colonel Abdullahi Aden, a senior police officer, told Reuters.
Residents said they could still hear sporadic gunfire into the night.
African Union forces along with the Somali army launched a new offensive this year against al Shabaab, which is fighting to impose its strict interpretation of Islam on Somalia.
Several towns have been wrested back from the group but officials say the Islamists still control tracts of countryside and some settlements, from where they have been able to continue their guerrilla-style campaign.
The militants, who seek to impose their own harsh version of Islamic law, have also staged attacks outside the Horn of Africa state, including a raid on a Kenyan shopping mall in September that killed at least 67 people. (Addtional reporting by Abdi Sheikh in Mogadishu and Edmund Blair in Nairobi; Writing by Edmund Blair and George Obulutsa; Editing by Mark Heinrich)