UKIP's donor was not on the electoral register
The UK Independence Party has lost the latest stage of its battle to avoid having to repay donations of £363,697.
Gifts by retired bookmaker Alan Bown between December 2004 and January 2006 were illegal as he was not registered to vote, the Court of Appeal said.
Party leader Nigel Farage threatened to appeal against the ruling, saying: "There is a very real danger that this could put UKIP out of business."
If the money were forfeited it would go to the Treasury, not back to Mr Bown.
UKIP estimates its total bill, including legal costs, could reach £750,000.
Mr Farage said the party had nothing like that amount of money in its funds.
He told the BBC: "To effectively risk putting out of business [a party] which came second in the last set of national elections because one piece of paper was not filled in was not what this legislation was intended for.
"If we are not given leave to appeal or if we lose at appeal, well, we are going to have to have one hell of a whip round to keep the party in business."
Mr Bown says he was mistakenly taken off the electoral register in December 2004 and did not find out until December 2005 he was not on it. He was reinstated in February 2006.
In 2007, the Electoral Commission said it wanted UKIP to forfeit all Mr Bown's donations.
But Westminster Magistrates' Court had said the breach of rules was accidental and ordered the party to pay back only £18,481.
The commission then took the case to the Court of Appeal, arguing that all the donations should be forfeited.
Three judges have now ordered the magistrates' court to change its original decision.
Political party donors must be on the electoral register if they give more than £200.
This rule was enacted mainly to stop foreign donations, but judge Sir Paul Kennedy said: "Parliament having decided that the test of acceptability of a donation from an individual should be whether that individual was registered in an electoral register, it seems to me to be irrelevant whether an impermissible donor is or is not making a foreign donation."
He added: "The fact that UKIP accepted donations from Mr Bown without realising that he was no longer in an electoral register is also, to my mind, immaterial."
Following the judgement, Electoral Commission chief executive Peter Wardle said that "all parties also need to follow the rules. And these rules need to be clear, simple and easy to follow.
"Parliament decided that political parties should only be able to accept money from individuals if they are on a UK electoral register.
"This provides a straightforward test of whether they should accept money or not. They simply need to check the electoral register. The United Kingdom Independence Party did not take these simple steps."
Mr Bown had been on the electoral register in Thanet, Kent, but was removed apparently by mistake without his knowledge in December 2004.
UKIP, which has 13 MEPs, admitted breaking the law, but said it was because of a clerical error and that to order forfeiture of Mr Bown's donations would be disproportionate.