MOGADISHU (Reuters) - Al Shabaab Islamist militants rammed a car packed with explosives into a Somali army base southwest of the capital on Monday and stormed inside, killing at least 10 soldiers, the group and a military officer said.

The assault on a base 50 km (30 miles) outside Mogadishu was part of the group's campaign to try to topple the Western-backed government and impose its own strict interpretation of Islam.

"Heavy exchange of gunfire continued for hours," Major Ahmed Farah told Reuters from the nearby town of Afgooye. At least 12 al Shabaab fighters were killed, he added.

Al Shabaab spokesman Abdiasis Abu Musab said 30 soldiers had been killed in the raid that lasted several hours before his group's withdrew. He did not mention al Shabaab casualties.

The group often cites a higher death toll than officials.

On Sunday, the president’s office said in a statement the government destroyed an al Shabaab base used to store military supplies in a region south of Mogadishu without resistance.

(Reporting by Feisal Omar and Abdi Sheikh; Writing by George Obulutsa; Editing by Edmund Blair)