A deep sea treasure-hunting company has been ordered by a US judge to hand over half a million gold and silver coins to the government of Spain.
The company, Odyssey Marine Exploration, raised the haul from a shipwreck in the Atlantic, suspected to be that of a Spanish naval vessel.
The Spanish government argued that the treasure formed part of the country's national heritage.
But Odyssey intends to appeal, saying it has a claim to the treasure.
This is just the latest round of a long-running and sometimes murky dispute, says the BBC's Steve Kingstone in Madrid.
The haul of coins - thought to be worth some $500m (£308m) - came to light in 2007, when Odyssey announced the recovery of artefacts from a wreck in the Atlantic.
It kept the location of the wreck secret, in what it said was an attempt to deter looters.
The haul was brought ashore in Gibraltar and quickly flown to Miami - enraging the Spanish government, our correspondent says, which says the wreck is that of the Mercedes, a naval frigate destroyed by the British in 1804.
Just over a year ago, the Spanish government filed a suit with a federal court in Florida - where Odyssey is based - demanding the haul be handed over.
Late on Wednesday, a judge ruled that the court lacked jurisdiction over the case, and that the property should be returned to Spain under a principle known as "sovereign immunity".
Spain's Culture Minister Angeles Gonzalez-Sinde expressed joy at the decision.
"It's a very positive decision for the Spanish government and for all the Spanish citizens because it guarantees that this ship and the remains of this ship will come back to Spain, which was originally the owner of this ship," he told the BBC.
"I am pretty sure that Spaniards will have the opportunity to travel back in time and to have a chance to see this treasure."
But in a statement, Odyssey said it would appeal against the ruling.
The Nasdaq-listed company argues that there is no conclusive proof that the wreck is that of the Mercedes and that even if it is, much of the cargo on board the ship belonged to private individuals and not the Spanish state.
"I'm confident that ultimately the judge or the appellate court will see the legal and evidentiary flaws in Spain's claim, and we'll be back to argue the merits of the case," said the firm's CEO, Greg Stemm.