A suicide bomber driving a car targeted the gates of the base near Mogadishu Stadium, military officials said.
The extremely loud explosion was heard across the city.
Islamist militant group Al-Shabab said it was behind the attack. It often carries out bombings targeting security forces and officials.
Col Ahmed Muse told Associated Press that the explosion took place at the gates of the 12th April Army Brigade base close to the recently reopened sports stadium in the Warta-Nabadda district.
The stadium opened in June and was seen as a symbol of the country rebuilding after years of conflict.
Halima Abdisalan, a mother of three who lives near the area told Reuters news agency that soldiers opened fire after the explosion. “We ran indoors in fear,” she said.
Al-Shabab – a group of Islamist militants, allied to Al-Qaeda – has waged an insurgency for more than 10 years. It was forced out of the capital in 2011 but still controls areas of the country.
Hitting a military base is an audacious act which is likely to worry the government, BBC World Service Africa editor Will Ross reports.
International peacekeepers from an African Union force have also been targeted in the past.