Al-Shabab accused him of committing blasphemy last year and threatened to kill him after he posted controversial videos on YouTube. Religious leaders criticized him for posting videos that showed the cleric pointing to a picture some thought represented the Prophet Muhammad. He was also condemned for using music in his worship services.
Via an affiliate website, the al-Shabab militant group claimed responsibility for killing the cleric.
Security forces have launched an attack on the militants, killing two. A third militant reportedly has been apprehended.
A journalist at the scene said security forces have taken control of the compound and have been collecting the bodies.