At least 21 security officers among 43 dead in firefight after attack by fighters on military barracks and mosque.