Lawyers for the men challenged the piracy charge, which was brought under a law dating back to 1819, and Judge Raymond Jackson agreed to throw it out because their conduct did not include robbing, boarding, or taking control of the USS Ashland warship.
"The court finds that the government has failed to establish that any unauthorized acts of violence or aggression committed on the high seas constitutes piracy as defined by the law," Jackson said in a 21-page ruling.
Prosecutors accused the six men aboard a small skiff in the Gulf of Aden of opening fire on the USS Ashland, a warship that supports amphibious operations. The U.S. vessel returned fire, sunk the skiff, killed one person and captured the others.
The piracy charge carried a mandatory penalty of life in prison if convicted.
The men were also charged with other crimes, including attacking to plunder a vessel, acts of violence against people on a vessel, conspiracy and assault with a dangerous weapon on U.S. officers and employees.
A Justice Department spokesman said the agency was reviewing the ruling and noted that the judge had refused to dismiss the other charges against the group.
"We will obviously be moving forward with the prosecution of the case -- and we will consider any options we may have with today's ruling," said spokesman Dean Boyd. Their trial is slated to begin in October.
The six men, and a group of five other Somalis captured after allegedly firing on another U.S. warship, were brought to Norfolk, Virginia, where they were charged in U.S. criminal court with the atstacks on the vessels.
Lawyers for the six Somalis accused of attacking the USS Ashland argued that the piracy charge should have been dropped because they did not board or take control of the warship or obtain anything of value from it.
Prosecutors countered that the act of piracy was broader and any unauthorized armed assault or violent act on the high seas was piracy.
"Following the government's assertions would subject the defendants to an enormously broad standard under a novel construction of the statute that has never been applied under United States law, and would in fact be contrary to Supreme Court case law," Jackson wrote.
Pirates have been operating off the coast of Somalia for years. They hijack ships including oil tankers in the Indian Ocean and the Gulf of Aden despite the presence of dozens of foreign naval vessels, and make tens of millions of dollars in ransoms.