A Spanish court has sentenced two Somalis to 439 years in jail each for the 2009 hijacking of a Spanish fishing boat in the Indian Ocean, while claiming government-linked bodies paid a ransom to secure the release of the vessel and its crew.

But Spain's foreign minister, Trinidad Jiménez, quickly contradicted the court and denied the government had paid to secure the release of the Alakrana.

The tuna fishing boat with a 36-member crew was seized off Somalia and held for 47 days. An alleged $3.3m ransom was paid. Spain says it does not pay ransom, but in the Alakrana case, the government said on the day of the release it did what it had to do. It did not elaborate.

Spanish commandos captured two men as they sailed away from the boat during the hijacking drama and they were brought to Madrid for trial. The National Court identified them as Cabdiweli Cabdullahi and Raageggesey Hassan Aji.

Jiménez told reporters that "the government did not pay ransom in the Alakrana case" and insisted this is what officials had said all along.

However, the 50-page court verdict says the trial "had shown beyond a shadow of a doubt that it was not the ship's owner but public organisations linked to the government which paid for the release of the crew and the ship".