MOGADISHU - Shebab militants launched a major suicide attack on Sunday against a military intelligence and training base in Somalia's capital Mogadishu, setting off a car bomb before storming inside, security officials said.

The interior ministry said the three attackers, one of them a suicide bomber, were all killed in the raid, and that the Somali security forces who fought them suffered no casualties.

A spokesman for the Al-Qaeda-affiliated militants confirmed they carried out the attack, Somali media reports said.

"There was an attack against a base belonging to the security forces. The violent elements used a car bomb to get inside the compound. There was a heavy exchange of gunfire," said Adan Mohamed, a Somali security official.

Witnesses near the base, which belongs to the internationally-backed government's National Intelligence and Security Agency (NISA), reported a loud explosion followed by intense gunfire.

"There was a heavy explosion and in seconds heavy gunfire broke out. We cannot go outside the house because of the shooting," said Abdulahi Yare, a resident who lives near the base.

In a brief statement, NISA said the attack had failed. "The attack was successfully thwarted by our forces. None of our buildings nor bases were entered," it said.

Somali officials also displayed three corpses after the attack, which came at the start of Islam's holy fasting month of Ramadan - a period when the the Shebab, who are fighting to topple the Mogadishu government, have in the past intensified attacks.

"The security forces have foiled an attempted attack by the desperate terrorists," interior ministry spokesman Mohamed Yusuf told reporters.

"One of them detonated himself and two others were shot dead. They were trying to storm the premises but they have been taken out before they reached their objective. There was no casualty on our side," he added.

In a separate attack in neighbouring Kenya, suspected Shebab militants gunned down a government administrator in the country's restive northeast, Kenyan police said.

Mohamed Barre Abdullahi, a local chief in Wajir, which is close to the Somali border, was shot dead after finishing evening prayers at a mosque on Saturday.

"The assailants trailed him to the mosque before taking cover to wait for him as he was praying.

They then followed him until he was some short distance away from the place of worship, before pulling the trigger," said Wajir County police commander Samuel Mukindia.

He said the attackers managed to escape under cover of darkness.

Kenyan security sources said the attack was likely carried out by the Shebab, who have stepped up operations in Kenya's northeastern border region, including drawing up an alleged "hit list" of local government officials who have spoken out against the group.

The Shebab, meaning "youth" in Arabic, emerged out of a bitter insurgency against Ethiopia, whose troops entered Somalia in a 2006 US-backed invasion to topple the Islamic Courts Union that was then controlling the capital Mogadishu.

Shebab rebels continue to stage frequent attacks, seeking to counter claims that they are close to defeat after losing territory in the face of an African Union and Somali government offensive, regular US drone strikes against their leaders and defections.

The group have also carried out a string of revenge attacks in neighbouring countries - including the September 2013 attack on the Westgate shopping mall in the Kenyan capital Nairobi, which left at least 67 dead, and the April massacre of close to 150 students in Garissa in Kenya's northeast.

Somalia has been wracked by instability since the collapse of Siad Barre's hardline regime in 1991.

The country's new government is being supported by a 22,000-strong AU force that includes troops from Burundi, Djibouti, Ethiopia, Kenya and Uganda.