A suicide bomber dressed in an army uniform infiltrated a training camp in Somalia's capital on Monday and killed at least nine soldiers, according to officials.

The bomber, posing as a military trainee, walked into the camp on the outskirts of Mogadishu and detonated explosives strapped to his waist.

Armed group al-Shabab, which has carried out frequent attacks aimed at overthrowing Somalia's internationally recognised government, claimed responsibility for the attack.

READ MORE: New army chief survives deadly Mogadishu bomb blast

Two military colonels were among those died, as well as the camp's chief trainer, Colonel Abdi Hassan told the Associated Press news agency.

A military colonel, asking not to be named, told the Reuters news agency: "Some of the injured ones are in serious condition. It is not easy to prevent a militant in military uniform who wants to kill himself."

At a hospital in Mogadishu, gravely wounded soldiers were transported to emergency rooms, with bleeding victims on stretchers awaiting treatment outside.

"He entered the camp unstopped," whispered an injured soldier with bandages wrapped around his head and leg as he spoke to his mother.

"We were sitting under a tree when he came and blew himself up among us," he said, grimacing with pain.

The soldiers and officers were resting after their daily military exercises.

In a separate incident on Monday, a government worker was killed after a bomb in his car was detonated by remote control in Mogadishu's Hamarweyne district, police said.

Al-Shabab has stepped up its campaign of bombings in Mogadishu in recent weeks; a car bomb targeting Somalia's new army chief left 15 people dead on Sunday, and a landmine killed 19 on Thursday.

The latest attacks come after President Mohamed Abdullahi Mohamed declared a new war against the group, naming a new military chief and other officials in an attempt to improve the worsening security situation.

Al-Shabab has denounced Mohamed, who was elected president in February, as an "apostate" and threatened to wage "vicious war" against his government.

The group was pushed out of Mogadishu by national and African Union multinational forces in 2011, but it continues to carry out deadly bombings. Targets have included hotels, military checkpoints and the presidential palace.

The conflict has exacerbated the effects of a severe regional drought in many parts of the country. The United Nations says more than half the population of 12 million will need aid by July.