SEOUL, South Korea – At dawn Friday, South Korean commandos steered their boat to a hijacked freighter in the Arabian Sea. Under covering fire from a destroyer and a Lynx helicopter, they scrambled up a ladder onto the ship, where Somali pirates were armed with assault rifles and anti-tank missiles.

Five hours after the risky rescue began, it was over.

All 21 hostages were freed from the gunfire-scarred freighter. Eight pirates were killed and five were captured in what President Lee Myung-bak called a “perfect operation.”

It was a remarkable ending to the daring and rare raid, handing South Korea a stunning success in the battle against pirates who have long tormented shipping in the waters off the Horn of Africa.

The lone casualty among the crew was the captain, identified as Seok Bae-gyun, 58, who was shot in the stomach by a pirate, South Korea’s JoongAng Ilbo newspaper reported. He was taken by a U.S. helicopter to a nearby country for treatment, but the wound was not life-threatening, Lt. Gen. Lee Sung-ho of the South Korean Joint Chiefs of Staff told reporters in Seoul.

“My heart stopped when the news of all the members being rescued was broadcast,” the captain’s son, Seok Hyun-wook, told the newspaper. “If I knew that they were planning a rescue, I would have been nervous all along.”

The successful raid also was a triumph for South Korea’s president and military. Both came under harsh criticism at home for being too slow and weak in the response to a North Korean attack in November on a South Korean island near disputed waters that killed two marines and two civilians.

Friday’s operation came a week after the Somali attackers seized the Samho Jewelry, a 11,500-ton chemical carrier sailing from the United Arab Emirates to Sri Lanka.

“We will not tolerate any behavior that threatens the lives and safety of our people in the future,” President Lee said in a brief televised statement.

Friday’s raid marked the first rescue operation since 2009 by a South Korean navy vessel deployed in the Gulf of Aden to help fight piracy.

“This operation demonstrated our government’s strong will to never negotiate with pirates,” Gen. Lee said.

The Bahrain-based U.S. 5th Fleet said the U.S. Navy was aware of the rescue, but referred all other questions to South Korea.

The Samho Jewelry was the second vessel from South Korea-based Samho Shipping to be hijacked in recent months. The company did not respond to a request for comment.