The U.S. navy released a photo of Maersk Alabama Capt. Richard Phillips on the USS Bainbridge after being rescued by Navy Seals off the coast of Somalia. ((Associated Press/U.S. navy))

The U.S. Navy SEALs fired on Somalian pirates to end a tense standoff on the high seas Sunday, rescuing an American sea captain who had been held hostage in a lifeboat after a failed hijacking.

Three pirates were killed and a fourth was injured in the mission to rescue Capt. Richard Phillips, 53, who was taken hostage last Wednesday off the coast of Somalia.

Vice-Admiral William Gortney told reporters Sunday that an on-scene commander with the U.S. Special Operations Command forces determined Phillips was in "imminent danger" after an AK-47 was aimed at the captain's back, so the commander gave the order for Navy SEALs aboard the USS Bainbridge to fire at the pirates on a lifeboat that was about 25 to 30 metres away.

U.S. President Barack Obama, who had given the military the authority to try to rescue the captain Friday and Saturday, said in a release Sunday, "I share the country's admiration for the bravery of Capt. Phillips and his selfless concerns for his crew."

After the rescue, Phillips was brought aboard the USS Bainbridge and then flown to the USS Boxer, where he showered, called his family and had a medical examination, Gortney said, adding the captain is in "good health."

The captain, who surrendered himself last week to Somalian pirates to save his U.S. crew, told his boss that his rescuers were the real heroes.

"I'm just the byline. The heroes are the navy, the SEALs and those that have brought me home," he told Maersk Line Ltd. chief executive John Reinhart, who relayed the message to reporters hours after Phillips's rescue.

The military will work with the Somalian government to determine what to do with the bodies of the dead pirates, Gortney said. The lone surviving pirate is in military custody and could face life in a U.S. prison, FBI spokesman John Miller said.

Ship was heading to Kenya

Phillips's ordeal began Wednesday after his ship, the U.S.-flagged Maersk Alabama, was attacked while on its way to Mombasa, Kenya, with a cargo of food aid and 20 U.S. crew members.

The ship at the time was off the Horn of Africa in the Indian Ocean, 560 kilometres from Somalia's coast.

Somalian pirates boarded and briefly took control of the ship. The unarmed crew thwarted the hijackers, who fled to a ship lifeboat with Phillips.

Since then, Somalian clan elders had been trying to negotiate a free passage for the hijackers in exchange for Phillips's freedom.

Early Sunday afternoon, Maersk CEO Reinhart said in a release that the U.S. government had informed the company that Phillips had been rescued. Reinhart said the company called Phillips's wife, Andrea, to tell her the news.

Tense negotiations

At one point on the weekend, talks broke down over the U.S. insistence that the pirates must be arrested and brought to justice.

American warships and helicopters had been keeping a close watch on the lifeboat that was holding the captain and his captors. The lifeboat was out of fuel and drifting.

On Friday, Phillips had tried to escape by jumping off the lifeboat and swimming, unidentified U.S. Defence Department officials said.

But he returned to the lifeboat after one of the pirates fired an automatic weapon, the officials said, although it was not clear whether shots were fired at Phillips or into the air.

On Saturday, the 19 U.S. sailors who escaped the pirate hijacking reached harbour in Mombasa. They credited Phillips with saving their lives.

Crew members said Phillips told his crew to lock themselves in a cabin. He then surrendered himself to safeguard his men.

With files from the Associated Press