Seven more suffered injuries in the assault in Abyan province and were taken to a hospital.

The militants attacked the compound from three sides, drove a bomb-laden vehicle inside and detonated it. The compound's main building was heavily damaged, the officials said.

Militants and soldiers exchanged gunfire for more than an hour.

The attack may have caught soldiers who were celebrating the high Muslim holiday of Eid off guard, an official said. But it had warned them in brochures ahead of time not to defend Yemen's government, which it accuses of being aligned with the United States.

Abyan province was considered a hub for al Qaeda militants throughout Yemen's political turmoil in 2011. After coming to power in February of 2012, President Abdu Rabu Mansour Hadi launched offensives against the Islamist extremists, uprooting its strongholds in southern Yemen.

Militants fled but left behind many sleeper cells.

"It's very difficult to fight al Qaeda in Abyan because they live within the society there," said AbdulSalam Mohammed, President of the Sanaa-based Abaad Research Center.

On Thursday, at least four soldiers were killed when al Qaeda militants attacked a large security base in the southwestern province of al-Baitha. Militants drove soldiers out and seized heavy artillery and armored vehicles.