Barcelona: A Spanish court said Friday it had replaced with fines the prison sentences handed down for tax fraud to FC Barcelona's star striker Lionel Messi and his father.

Messi, the best paid footballer in the world according to the club, and his father had been convicted of hiding image rights royalties in offshore accounts and had been given jail terms of 21 and 15 months respectively.

File photo of Lionel Messi. Getty

Following Friday's ruling by Barcelona provincial court, Messi will instead pay €252,000 ($287,000) and his father €180,000 in fines.

Under the original sentence, neither Messi nor his father would ever have had to actually serve time behind bars, because in Spain first offenders for non-violent crimes are spared jail time for sentence of less than two years.

The two were in July 2016 found guilty of using companies in Belize, Britain, Switzerland and Uruguay to avoid paying 4.1 million euros in taxes on income Messi earned from his image rights from 2007-09.

The income relates to Messi's endorsement deals including with Danone, Adidas, Pepsi-Cola, Procter & Gamble and the Kuwait Food Company.

The player and his father made a voluntary payment of five million euros -- equal to the amount of the alleged unpaid taxes plus interest -- in August 2013 after being formally investigated. They were also fined around 3.5 million euro for that fraud.

The Barcelona court said it took these payments into account when deciding to exchange their prison sentence for new fines.

"This made them both deserving of having the prison sentence substituted by a fine, "the court said in a ruling released on Friday.

The ruling caps off a golden week for Messi, who on Wednesday extended his contract with FC Barcelona until June 2021, just days after he married his childhood sweetheart in Argentina.

The club did not give financial details but club president Josep Maria Bartomeu said Messi was the best paid player in the world.

Prior to his contract extension, Messi was the third highest paid sportsman in the world with an income of $80 million of which 53 million was in salary and bonuses, according the ranking published by Forbes magazine in June.