The incident raised fears that hostages could have been hurt in the crossfire.
This is the first time Somali pirates have taken over a commercial ship since 2012 and locals blame the attack on foreign fishermen flooding into their waters. The Somalis are also angry with their government for licensing some of the ships.
"We tried to intercept a boat that was carrying supplies to the pirates, but pirates on the ship fired on us and so the pirate boat escaped," said Abdirahman Mohamud Hassan, the director general of the maritime force in Puntland.
"We shall kill the crew if Puntland forces fire on us again," pirate Abdullahi told Reuters.
Residents near the ship, which was hijacked on Monday with eight Sri Lankan crew aboard, said four civilians were injured by stray bullets from the fight.
“My brother called and said the coast guards have surrounded the area where they have been held and asked them to leave," the brother of one hostage, who asked not to be identified, told Reuters by phone from Colombo.
In their heyday in 2011, Somali pirates launched 237 attacks off the coast of Somalia, data from the International Maritime Bureau showed, and held hundreds of hostages.
But attacks fell sharply after crews put safety measures into place and regional naval forces stepped up patrols. Some pirates returned to fishing, and others became involved in smuggling people and weapons.