One soldier was also wounded in the attack, the official, who requested anonymity, told Puntland Mirror.
The gunmen run away the scene after the shooting, the official added.
No group has immediately claimed the responsibility for the attack, but terrorist militants like Al-Shabab and ISIS carries out frequent attacks in the port town of Bosaso.