It is the latest in a series of raids in Mogadishu by the group which wants to topple the Western-backed government and impose its own strict version of Islamic law.
The group also attacked a university campus in neighboring Kenya this month, killing 148 people.
"First two blasts occurred, a bike blast and a car blast, outside the building, then armed fighters stormed in," Major Ali Nur, a police officer, told Reuters.
He was speaking as fighting still raged around the building that houses the Higher Education Ministry and the Petroleum and Minerals Ministry. About an hour and a half after the explosions, police said they had secured the building.