The Supreme Court ruled Friday that a man who lost a large sum of money placing online horse race bets should be able to treat his losses as tax deductible, rejecting an appeal by the state.

The decision was in line with the top court’s ruling in March 2015 that found costs for the purchase of horse race slips that proved unsuccessful could be treated as tax deductible if the tickets were “bought on a regular basis for the purpose of making profits.”

After that landmark decision, the National Tax Agency issued a notice listing the use of software for the automatic purchase of horse race betting tickets as a condition for the tax deduction to be applied for such failed bets.

But in the latest ruling, the top court accepted the claim of the plaintiff, a civil servant from Hokkaido in his 40s, despite the fact that he did not use such software.

According to a Tokyo High Court ruling, the man bought betting slips worth ¥7.27 billion ($64.8 million) in total from 2005 to 2010 online for a net gain of around ¥570 million.

He reported his gains to tax authorities, treating the money spent on unsuccessful bets as costs, but the authorities did not recognize his losses as expenses and taxed him around ¥190 million more.

The man filed a lawsuit to challenge the additional tax with the Tokyo District Court. The district court rejected his claim in May 2015 and said the additional tax was lawful, saying his method for purchasing the tickets did not differ significantly from general horse race betting. The man appealed the ruling to a higher court. The Tokyo High Court reversed the lower court’s decision in April 2016, ordering the state to cancel the additional tax. The state appealed to the Supreme Court.

In a separate case in Osaka that continued from 2013 to 2015, a former company employee from the city of Osaka sued the state to seek the reversal of a similar taxation, claiming that unsuccessful bets should be considered expenses and that he should not be taxed more than he had the ability to pay. According to the lawsuit, the plaintiff spent ¥3.5 billion on betting slips online and collected ¥3.66 billion in winnings over a period from 2005 to 2009.

As expenses, however, tax authorities deducted from his income the ¥150 million he had spent on the winning betting slips, levying ¥680 million in income tax, plus a ¥130 million penalty tax for failing to declare income.