US Navy snipers made a split-second decision to shoot dead three Somali pirates holding a cargo ship captain hostage on a lifeboat, officials say.
US Navy spokesman Vice-Adm William Gortney said the pirates were shot because Capt Richard Phillips' life appeared in "imminent danger".
Snipers on a US warship towing the lifeboat fired after seeing a pirate pointing a gun at him, the navy said.
Capt Phillips was not hurt, and a fourth pirate surrendered.
The US Navy had had contact with the pirates as the stand-off continued, attaching a tow rope and taking one pirate on board for medical help.
Negotiations involving Somali elders had been going on throughout Sunday to secure the captain's release, with the fourth pirate still on board the USS Bainbridge.
He was taken into military custody.
The lifeboat, which had no power, was attached on a tow line about 100 ft (27 metres) behind the warship after the pirates had accepted an offer to be moved out of rough seas.
One pirate was seen through a window pointing an AK-47 at the back of Capt Phillips, who was tied up.
The commander ordered the shooting, with snipers aiming at the pirates' heads and shoulders when two of them appeared at the rear hatch, Vice Admiral Gortney said.
It was unclear how long the shooting lasted, with some reports saying it was several minutes, while the New York Times reported that three single shots were all that were needed.
Navy sailors then sailed to the lifeboat in a small inflatable craft and rescued Capt Philips.
He was unhurt despite being just a few metres away from his captors during the shooting.
He was then taken on board the Bainbridge, and later moved to the USS Boxer where he underwent a medical examination.
Capt Phillips had been held hostage in the lifeboat since Wednesday, when pirates attacked his ship, the Maersk Alabama.
He had agreed to become a hostage so that his crew could go free, the crew said.
Vice-Adm Gortney said the pirates were armed with AK-47 assault rifles and small-calibre pistols.
US President Barack Obama had given clear orders to shoot if Capt Phillips' life was in danger, he said.