The attack occurred yesterday at a military base in the Yaq-Bariweyne area about 100 kilometres south of the capital Mogadishu.
"Several of the militants were also killed during the fighting," said Mohamed Adan, a Somali military official.
Witnesses said the militants overran the camp, looted military supplies and then left.
"The Shebab fighters took control of the camp and looted everything. The commanders addressed residents of the village, they said the rule of Sharia law will be back soon," said Abdirahman Somow, a local eyewitness.
The Shebab, who have recently lost a string of key bases in the face of an offensive by the African Union's AMISOM force, has stepped up counter attacks involving hit-and-run raids on several bases, including an attack on an African Union camp earlier this month that left at least 50 dead.
The Shebab is fighting to overthrow the internationally backed government in Mogadishu, which is protected by 22,000 AMISOM troops from Burundi, Djibouti, Ethiopia, Kenya and Uganda.