South Korean navy commandos have stormed a cargo ship which had been seized by pirates in the Arabian Sea.
All 21 crew members of the South Korean-owned Samho Jewelry were rescued, said Lt Gen Lee Sung-ho of the Joint Chiefs of Staff.
The navy said eight of the pirates had been killed and five captured.
South Korea is part of a multinational anti-piracy patrol in the area - it had dispatched a warship after the vessel was seized on Saturday.
The unprecedented rescue mission took place about 1,300km (800 miles) off the coast of Somalia and was described by Lt Gen Lee as "a perfect military operation".
The 11,500-tonne Samho Jewelry had been carrying chemicals from the United Arab Emirates towards Sri Lanka when it was hijacked in the waters between Oman and India.
Earlier in the week, President Lee Myung-Bak told the navy to take "all possible measures" to free the eight South Koreans, two Indonesians and 11 Burmese on board.
The Choi Young destroyer had been pursuing the ship for nearly a week, and the navy said the pirates appeared to have been weakened by the chase.
Lt Gen Lee said there were also concerns that they were expecting a mother ship to arrive soon to give them support.
"Since we thought we could be in an extremely difficult situation if the pirates joined forces, we chose today to carry out the operation," he said.
Lt Gen Lee said the South Korean Joint Chiefs of Staff had taken advice from the Fifth Fleet - the US Navy division based in Bahrain - before the mission, and that the raid was carried out with support from a US destroyer.
The Choi Young moved in when some of the pirates left the Samho Jewelry, apparently to attack a Mongolian ship nearby.
Commandos boarded the ship while a smaller boat and a helicopter were sent to rescue to Mongolian vessel.
"Three of our soldiers suffered light scratches on their bodies as they were fired upon by pirates on Tuesday," said Col Lee Bung-Woo, a spokesman for the Joint Chiefs of Staff.
"Our Lynx helicopter immediately returned fire and several pirates fell into the waters. We believe they are dead."
Officials said eight of the 13 pirates on board were killed, although their bodies have not been found. Five were captured alive.
The captain of the ship suffered a bullet wound to the stomach but his condition was not thought to be life-threatening - he was praised for his actions in assisting the rescue.
"Pirates sought to take the vessel to the Somalian coast fast but the skipper helped us earn time by manoevering the vessel in a serpentine manner," said Lt Gen Lee.
"This operation demonstrated our government's strong will to never negotiate with pirates," he said.
In a televised statement after the mission, South Korean President Lee Myung-bak said the military had "carried out the operation perfectly under difficult circumstances".
"I appreciate it and send a message of encouragement," he said.
"We will not tolerate any behaviour that threatens the lives and safety of our people in the future."
Family members of the crew said the news of the rescue was "breathtaking".
"I feel so relieved," said the son of crew member Kim Doo-Chan. "I'm ecstatic."
The Gulf of Aden, between Yemen and Somalia, is one of the world's busiest shipping routes and has become a hotspot for pirate attacks.
Last year, Somali pirates received a record ransom of $9.5m (£5.8m) after seizing another ship owned by Samho Shipping.
The Samho Dream supertanker had been hijacked in the Indian Ocean in April.