Updated

MIAMI — A U.S. district judge has ruled that U.S. treasure-hunting company Odyssey Marine Exploration should return to Spain a fortune in old coins recovered from the wreck of a 19th-century Spanish warship.

In an order filed in Tampa, Florida Tuesday, Judge Steven Merryday nevertheless directed that the return of the treasure to Spain be stayed until an appeals process in the case was concluded. It was the latest twist in a complex dispute over the treasure involving Spain, Odyssey and Peru.

Merryday's order backed a recommendation by a U.S. magistrate judge in June that Odyssey should hand over to the Spanish government nearly 600,000 silver and gold coins valued at some $500 million that it recovered from the wreck of the 19th-century Spanish warship Nuestra Senora de las Mercedes.

Spain said the Spanish naval frigate was carrying treasure back from Peru when it was sunk by British gunboats in 1804.

SLIDESHOW: Salvaging Treasure from the Wreck of the 'Black Swan'

Odyssey Marine, which has disputed the treasure came from the Nuestra Senora de las Mercedes, discovered wreckage and the 17-ton haul of artifacts in March 2007 in international waters about 100 miles west of the Straits of Gibraltar, which separate Spain from North Africa.

"The ineffable truth of this case is that the Mercedes is a naval vessel of Spain and that the wreck of this naval vessel, the vessel's cargo, and any human remains are the natural and legal patrimony of Spain," Merryday said in his order.

Odyssey, which specializes in the recovery of sunken treasure and had codenamed this particular project "Black Swan," says the coin haul legally belongs to the company.

Odyssey said in a statement Wednesday that Merryday's ruling would for the time being keep the coins in Odyssey's custody pending an appeals ruling by the U.S. Eleventh Circuit Court of Appeals.

"Judge Merryday's ruling serves to move this case to the appellate court faster, where we feel confident that the legal issues are clearly in our favor," Odyssey CEO Greg Stemm said.

"We will file our notice of appeal with the Federal District Court for the Middle District of Florida and Eleventh Circuit Court of Appeals within the required time and look forward to presenting our case in that forum," said Melinda MacConnel, Odyssey vice president and general counsel.

The Mercedes sank in the first few minutes of the Battle of Cape St. Mary's as an explosion ripped it apart, killing more than 200 sailors. The attack led Spain to declare war on Britain and enter the Napoleonic Wars on the side of France.

Peru, which was ruled by Spain at the time the Mercedes was sunk, entered the legal fray in August when it filed a claim for information with the Tampa court. The filing said the coins may be "part of the patrimony of the Republic of Peru."

Judge Merryday also backed the magistrate judge's June recommendation that Spain and Peru's competing claims over the coins would be best resolved through direct negotiations and not in a U.S. court.