The group's media arm, al-Malahim, said the ministry complex in Sanaa had been targeted because US unmanned drones were being operated from there.
The attack saw a suicide bomber ram an explosives-filled car into the main gate before gunmen launched an assault.
Among the dead were soldiers and civilians, including seven foreigners.
It was the deadliest attack in Sanaa since May 2012, when a suicide bomber blew himself up during a rehearsal for a military parade.
'Heavy blow'
Thursday's attack in the Bab al-Yaman district, on the edge of Sanaa's old city, began at about 09:00 (06:00 GMT) with a huge car bomb explosion at the entrance to the defence ministry's command complex, one of the government's most important security facilities.
About a dozen militants then stormed the compound, targeting civilians working at a military hospital inside or receiving treatment there.
The BBC's Shaimaa Khalil describes "plumes of smoke and gunfire" at the scene
Two doctors from Germany, two others from Vietnam, as well as two nurses from the Philippines and one nurse from India were among those killed, the official Saba news agency reported.
The Philippine foreign ministry said seven of its nationals had died.
Other civilian victims included a top Yemeni judge and his wife, and one of President Abdrabbuh Mansour Hadi's relatives.
Security forces later retook the complex after killing the attackers.