The two men were part of a group of nine pirates who were in a boast approaching an unidentified ship near the Gulf of Aden when a naval force opened fire on them, said Ahmed Abdullahi, an official with the anti-piracy force in Puntland, a semi-autonomous part of Somalia.
The six other pirates survived the attack and escaped, he said.
Residents in Durduri, a coastal village in Sanaag region, said they found two dead bodies left by the pirates near the coast on Sunday morning.
In recent weeks there has been a resurgence of piracy off Somalia's coast, after five years of inactivity.
In a separate incident in Somalia, a roadside bomb on Sunday struck a convoy carrying officials from the World Food Program on the outskirts of Mogadishu, injuring two bodyguards, a U.N. official said.
The U.N. officials were on a supervision mission outside Mogadishu at the time of the attack, the official said on condition of anonymity because he was not authorized to speak to the press.
Copyright 2017 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.
2 pirates killed while trying to hijack ship near Somalia
By ABDI GULED Associated Press MOGADISHU, Somalia (AP) - Foreign naval forces in international waters off Somalia's coast shot dead two pirates and wounded another when the bandits attempted to hijack a ship, a Somali official said Sunday.