The official said the attacker threw himself into a crowd of cadets leaving the academy on Wednesday after class. Ambulances could be seen rushing to the site.
He said dozens more were injured, including seven critically. He spoke on condition of anonymity because of regulations.
Yemen's military is on the offensive against the radical al-Qaida group's Yemen branch, considered the terror network's most dangerous offshoot. The army has recently retaken several al-Qaida-held towns in the south.
The network has struck back with attacks in the south and a May 21 bombing at a parade ground in Sanaa that killed 96 Yemeni soldiers.