"We arrested seven pirates after they killed the captain of the ship."

Two Somali soldiers were injured in the gun battle, which freed 24 crew members from Egypt, Pakistan, Bangladesh and Ghana.

In depth



 The pirate kings of Puntland 
 
Q&A: Return to Somalia
 Q&A: Piracy in the Gulf of Aden
Timeline: Somalia

Videos:
 
Life inside the den of Somalia's pirates
 Lucrative raids lure Somali youth
 Meet the pirates
 Somalia guard struggles to combat piracy

Somali forces decided to use force after the pirates refused to surrender, Raage said.

The ship was carrying sugar from Brazil to Bossaso, a city in northern Somalia, he said.

The 15,220 tonne MV QSM Dubai was captured by pirates while it was travelling inside of the internationally recommended transit corridor.

Puntland, a semi-autonomous region in northern Somalia, is a base for pirate gangs targeting ships in the Gulf of Aden.

But the area is generally more peaceful than the rest of the country.