Lawyers for five Somali men accused of piracy have told a US court that they did not attack a US Navy ship as charged, but fired their guns to attract attention and get help.
Prosecutors say they mistook USS Nicholas for a merchant ship and tried to seize it to get a ransom.
Legal scholars say it is the first piracy trial in the US for 100 years.
Warships from several countries are patrolling the Indian Ocean to ward off attacks by Somali pirates.
Another Somali man pleaded guilty to piracy in May but that case did not go to trial.
With piracy increasing, there have been calls for international courts to be set up to deal with the problem.
Some suspected pirates are set free because of the complications involved in prosecuting them.
Neighbouring Kenya has tried several pirate cases but a court this week ruled it had no jurisdiction for those captured in international waters.
Prosecutor John S Davis told the court in Norfolk, Virginia, that the five men had confessed when they were first apprehended, reports the AP news agency.
He said they fired assault rifles at the USS Nicholas but fled after sailors returned fire with machine guns.
He said they were hoping for a ransom of between $10,000 (£6,200) and $40,000 (£24,800).
But lawyers for the men say they were fishermen who had been forced by pirates to attack the ship.
"They were trying to escape from the pirates and seek some help," said defence lawyer William J Holmes.
Another defence lawyer argued that it is absurd to think that people could mistake a warship for a merchant vessel, AP reports.
The charges against the men include piracy, attacking to plunder a maritime vessel, and assault with a dangerous weapon.
Piracy carries a mandatory life sentence.
Norfolk is the home of the world's largest naval base and the home port of the Nicholas.
According to documents filed in the federal court, in March the crew of five young defendants, mostly fishermen in their mid-20s, set sail from Somalia in search of a merchant vessel to plunder.
Their ship carried food and fuel and had two smaller skiffs tied to it, which prosecutors say were to serve as attack craft. The men were armed with assault weapons and a rocket-propelled grenade, prosecutors said.
One of the defendants, Mohammed Mohdin Hassan, told investigators he had been promised $30,000 (£18,552) for a successful mission, according to court documents.
About eight days later, on the high seas and under cover of night, Mr Hasan, Gabul Abdullahi Ali and Abdi Wali Dire boarded one of the attack craft and set out to attack what they believed was a merchant ship.
In fact, the ship was the Nicholas, which had been deployed to the east coast of Africa on an anti-piracy mission.
Mr Hasan and Mr Dire brought the attack skiff close to the Nicholas and opened fire, prosecutors said. The Nicholas returned fire and gave chase, capturing the defendants and taking them aboard the ship and destroying their skiff.
In court documents, Mr Ali is described as an impoverished 26-year-old fisherman and Mr Dire, 26, is a former bus conductor turned fisherman, and is also impoverished. Lawyers for Mr Hasan say he does not know his age but have argued he was under 18 when he was captured and should be treated as a juvenile.
The five suspects were arrested in April, along with six others who were captured a few days later in waters near Djibouti after allegedly shooting at the USS Ashland, an amphibious vessel.