The militants “used a car bomb to get inside the compound,” Press TV quoted Adan Mohamed, a Somali security official, as saying.
The base is owned by the government-run National Intelligence and Security Agency.
Somalia’s Interior Ministry said three assailants were killed in the raid, while there were no casualties on the side of the Somali security forces.
Sunday’s raid came a day after the militants stormed a police post outside the capital killing eight officers.
Somalia has been the scene of deadly clashes between government forces and al-Shabab militants since 2006.