BOSASO, Somalia (Reuters) - Al Shabaab militants killed 38 people, mostly soldiers, in an attack on a military base in Somalia’s semi-autonomous Puntland region on Thursday, an army officer said.

The killings took place when the Islamists attacked and took over the town of Af Urur.

“Now we confirm 38 people, mostly soldiers, died and 18 others were wounded. I believe some were captured alive and taken away,” Major Mohamed Abdi, a Puntland military officer, told Reuters.

“Numerous, heavily armed al Shabaab fighters attacked us from every direction and after hours of fierce battle I was among those who ran for their lives.”

Bari regional Governor Yusuf Mohamed told Reuters the Puntland military had recaptured the town.

The assault came days after Puntland sentenced to death five al Shabaab members arrested on April 26 as they drove a vehicle carrying barrels packed with explosives into Bosaso, Puntland’s capital.

Af Urur lies about 100 km (60 miles) south of Bosaso, near the Galgala hills, an area controlled by al Shabaab. Its fighters have attacked and captured the town several times.

“Al Shabaab fighters killed local residents of the town including elders, women and children. It is the norm of al Shabaab to kill civilians when they are defeated,” a statement from the Puntland president’s office said.

“Al Shabaab will regret killing civilians. We shall eliminate the fighters who hide in Puntland areas.”

The al Qaeda-linked Islamist group said it had killed 61 soldiers after overrunning the military base. The numbers given by officials and al Shabaab often differ.

Abdiasis Abu Musab, a spokesman for al Shabaab, said the military had not recaptured Af Urur by force. “We just left it peacefully after killing 61 soldiers and capturing 16 military cars,” he said.

Al Shabaab more often launches attacks on the capital Mogadishu and other regions controlled by Somalia’s federal government. It aims to drive out African Union peacekeepers, topple the Western-backed government and impose its strict version of Islam.

Attacks are comparatively rare in Puntland, where the security forces are relatively regularly paid and receive substantial U.S. assistance.

The region is also home to a splinter group of al Shabaab that has sworn allegiance to Islamic State. Security sources say a small contingent of foreigners is there as well.