Security forces in northern Somalia have stormed a Panamanian-registered cargo ship that was seized by pirates last week, rescuing the crew unharmed.
Officials in the semi-autonomous Puntland region said local forces boarded the vessel after a gunfight in which two soldiers were wounded.
Ten gunmen on board surrendered after running out of ammunition.
Meanwhile, a Ukrainian vessel carrying 33 tanks is still being held by pirates demanding a $20m (£11m) ransom.
Earlier, the pirates said they would blow up the MV Faina unless the money was paid by Monday night.
A pirate spokesman later said the deadline may be extended following requests from the ship's owner and other officials.
Last Thursday, heavily armed pirates raided and seized control of the container ship, the Awail, carrying cement from Oman to Bossasso, the capital of Somalia's semi-autonomous region of Puntland.
Two days ago, Puntland security forces tried to board the ship.
But they did not succeed and one of their men and one pirate were killed.
On Tuesday they tried again. This time they managed to board the ship when the pirates ran out of ammunition.
According to officials from Puntland, none of the crew - nine Syrians and two Somalis - were injured.
The BBC's Peter Greste in neighbouring Kenya says retaking a hijacked ship is notoriously risky for both the vessel and the captive crew.
But Puntland now urgently needs to regain control of piracy, which has boomed in the past few months, he says.
Many pirate gangs are based in the Puntland town of Eyl.
More than 30 ships have been seized this year in the busy shipping lanes near to Somalia's coast and along the Gulf of Aden.
Somalia has lacked a functioning central government since 1991 and has been afflicted by continual civil strife.
Last week, Nato agreed to send seven frigates to combat piracy in the region.