The teachers were killed in a fire caused by the explosion in the attack at 1 a.m. (2200 GMT on Tuesday) at Arabia Boys Secondary School, police said on Twitter.
Police reservists guarding the school "engaged the attackers who then fled as more reinforcements were mobilized", police said.
The al Qaeda-linked al Shabaab aims to topple Somalia's U.N.-backed government and impose its own strict interpretation of Islam. They have intensified attacks in Kenya since it sent troops into Somalia in 2011.
(With inputs from agencies.)