The high court has ruled that the Electoral Commission misunderstood the law surrounding donations from the pro-Brexit group Vote Leave to Darren Grimes, the founder of BeLeave.

In a devastating judgment for the UK’s elections watchdog, the court found its interpretation of the law was inconsistent with both its language and purpose and said it had tried to draw a distinction that would be “a recipe for abuse of the spending restrictions”.

The Good Law Project, led by the barrister Jolyon Maugham QC, had sought a review of the commission’s decision to allow Vote Leave to donate to Grimes and not consider those funds to constitute its own spending.

Facebook Twitter Pinterest Jolyon Maugham QC. Photograph: Jolyon Maugham QC

Vote Leave has faced allegations of cheating during the Brexit referendum since it emerged that it had donated hundreds of thousands of pounds to Grimes, who then spent that money on the same political data consultancy as Vote Leave. The group would have exceeded spending restrictions had it spent the money itself.

Maugham said: “It is extraordinary that the body charged by parliament with ensuring the referendum was fair, acted unlawfully to ensure it was unfair.”

The judgment said the court had concluded that the commission misinterpreted the definition of “referendum expenses” in the legislation governing political campaign finance.

“The source of its error is a mistaken assumption that an individual or body which makes a donation to a permitted participant cannot thereby incur referendum expenses.

“As a result of this error, the Electoral Commission has interpreted the definition in a way that is inconsistent with both the language and the purpose of the legislation.”

Vote Leave, which has argued that it acted according to the commission’s guidance, said electoral law had been thrown “into total chaos” by the ruling.

“Either the Electoral Commission is wrong or the high court is wrong,” said Matthew Elliott, Vote Leave’s chief executive, who demanded that the commission retract its subsequent decision to fine the organisation over its donations to Grimes.

“Should the Electoral Commission choose not to appeal this judgment, they will be admitting that they gave Vote Leave incorrect advice and they should immediately reconsider the unfair fines they are seeking to impose on us because Vote Leave would not have made the donations that it did had it not been for the commission’s clear advice.

“This whole situation is a mess of the Electoral Commission’s own making, and their defeat in the high court today must force a rethink. They now have a chance to rectify their errors. They should do the right thing.”

An Electoral Commission spokesperson said it welcomed the court’s “consideration of this aspect of electoral law” and said it had reached the same conclusion as a subsequent commission investigation, which resulted in fines being issued to Vote Leave and Grimes.

“The court arrived at the same conclusion as the commission did in its investigation – that Vote Leave should have accounted for the expenditure on the digital services firm, Aggregate IQ – although it found an additional reason for reaching that conclusion,” the spokesperson said.

“The commission imposed sanctions on Vote Leave for this offence and others found during the investigation.”