A suicide car bomber rammed the gates of a restaurant near a beach in Somalia's capital before gunmen fought their way into the building in an attack claimed by an Islamic extremist group that killed at least three people on Thursday, a police official said.

The assailants may have taken some hostages inside the Liido Seafood restaurant, which is popular with Mogadishu's elite and government officials, Capt. Mohamed Hussein said. It wasn't immediately clear if any senior officials were trapped in the restaurant.

"The operation (to overpower the attackers) is ongoing now. The (attackers) are still inside and fighting our troops," Hussein said from the scene of the attack as gunfire rang out in the background. He said he had counted at least three bodies outside the restaurant.

An unknown number of people are still trapped inside the restaurant, and the death toll is likely to rise when the attack is over, he said, adding that darkness is hampering efforts by the security forces to overwhelm the assailants.

Gunfire could be heard inside the restaurant, suggesting that the gunmen were killing civilians trapped inside, he said.

"The place was packed when the (gunmen) came, so the number of casualties will probably rise," he said.

Islamic extremist group al-Shabaab claimed responsibility for the attack, in a broadcast on its online radio late Thursday.

Witnesses said that gunmen shouted "Allahu akbar," the Arabic phrase for "God is great," and entered the restaurant from the direction of the beach as clients, sitting behind razor wire, watched the seashore.

"They randomly fired at the people sitting near the beach before entering the restaurant," said witness Ahmed Nur, who was strolling along on the shoreline when the attack happened.

Al-Shabaab attacked Kenyan peacekeepers in southwestern Somalia last week. The al-Qaeda-linked group claimed it had killed about 100 Kenyans and seized armaments and military vehicles. The Kenyan government has given no death toll, saying broadly that there were some fatalities.

Despite being pushed out of Somalia's major cities and towns, al-Shabaab continues to launch deadly guerrilla attacks across the Horn of Africa country. African Union troops, government officials and foreigners are frequently targeted.