The U.S. Navy says fear that an American cargo ship captain's life was in imminent danger prompted U.S. gunfire that killed three Somali pirates and secured the captain's freedom after five harrowing days in captivity.

Late Sunday came word that Captain Richard Phillips, who offered himself as a hostage to secure the freedom of his crew aboard the Maersk Alabama, was unharmed aboard a U.S. Navy vessel.

Vice Admiral William Gortney of the U.S. Navy's 5th Fleet says elite special forces aboard the USS Bainbridge took action on orders from President Barack Obama to use deadly force, if Phillip's life was at stake.

"The pirates were armed with AK-47s and small-caliber pistols. And they were pointing the AK-47s at the captain. It got heated, and the on-scene commander interpreted hostile intent by the pirates and took the appropriate action," said Admiral Gortney.

The admiral says the pirates had been demanding a substantial ransom and repeatedly threatened to kill Phillips. Phillips and the pirates were aboard a lifeboat from the Alabama that had run out of fuel. A fourth pirate was on the Bainbridge at the time the stand-off ended.

Gortney said, "The one pirate who surrendered early today is being treated humanely. His counterparts [other pirates] who chose to continue to fight paid with their lives. And the [U.S.] Department of Justice is working out the details with the intent of holding him [i.e., the 4th pirate] accountable for his actions."

Gortney described Phillips and his crew as "heroic". But the head of Maersk Line, John Reinhart, who spoke with Phillips by telephone after the ordeal had ended, said the captain insisted the real heroes were the U.S. service members who "brought me home."

Phillips had tried to escape on his own, but the Somali pirates recaptured him.

At Captain Phillips' home in Vermont, there was jubilation. Family friend Alison McColl spoke to reporters. "This is truly a very happy Easter for the Philips family."

Phillips was the first American to be taken by pirates who have plagued the Gulf of Aden and Indian Ocean shipping lanes for years. Hundreds of other hostages of various nationalities are being held hostage by pirates.

The U.S. Navy's rescue of Phillips was the second time that Somali pirates have faced deadly military force this month. Last week, French forces killed two pirates and captured three others to end a hostage stand-off aboard a French yacht.

Commenting on the Phillips rescue, a self-proclaimed Somali pirate told the Associated Press that he and his fellow marauders have learned a lesson and that they will kill future hostages.