Somali pirates have released a hijacked oil tanker and its eight Sri Lankan crew, according to Somali security official and the pirates, bringing the first hijacking since 2012 to a conclusion, apparently without the payment of a ransom.

Thursday's release followed a gun battle earlier in the day between the pirates and the marine force, and then intensive negotiations between the marine force, clan elders and the pirates.

The hijacking was the first time Somali pirates have taken over a commercial ship since 2012 and followed an outpouring of anger by locals over foreign fishermen flooding into their waters.

The Somalis are also angry with their government for licensing some of the ships.

READ MORE: Somalia pirates - Anger fuels return of ship attacks

"There has been discussion going on after the gunfight of this afternoon ... We pulled our forces back and so the pirates went away," said Abdirahman Mohamud Hassan, director-general of the maritime police force for Somalia's semi-autonomous northern region of Puntland.

In previous hijackings, many crews remained in captivity for years before a ransom was paid. Eight Iranians are still being held.

But the pirates said they agreed to forgo a ransom after learning that Somali businessmen had hired the ship, which was taking oil from Djibouti to the Somali capital of Mogadishu.

Pirates have traditionally been wary of getting into disputes with Somalia's powerful businessmen.

READ MORE: The other side of Somalia's pirates

But locals say the attacks will continue and blame their government in Puntland for granting foreigners permits to fish in Somali waters.

Piracy in East Africa, especially Somalia, has been economically viable for hijackers who have netted $7bn since 2007, Abdinur Ali, a senior maritime security official in Puntland, told Anadolu Agency.

He said 1,000 hostages have been taken in that time.

Somalia has the longest coastal line in Africa and has witnessed a large number sea vessels targeted by Somali pirates.