A council is facing a seven-figure bill after a court ruled it underpaid private care homes for placements.
A judge agreed with a claim by a group of nearly 30 care homes that Torbay Council was paying them up to £70 less per person per week than neighbouring Devon County Council.
The Torbay Quality Care Forum (TQCF) said paying too little could cause staffing and maintenance problems.
The authority it would reflect on the High Court judge's ruling.
Accountants commissioned to report on the council's workings agreed with TQCF's claim that the authority had made "illogical mathematical errors" and TQCF won a judicial review at the High Court in London.
The judge agreed that the calculation it used was "fundamentally flawed".
TQCF estimates that the total cost to the council in increased funding for care homes next year will be about £3.5m.
Alan Beale, one of the directors of TQCF, said: "The bottom line is that the funding decision set at the start of this year for 2014/15 is ordered to be quashed.
"The judicial review has told the council to go away and do it again. It is a complete defeat for the council."
The Conservative-controlled council said in a statement: "This is a complicated case and Torbay Council will now carefully reflect on the judgement, its implications and what further action needs to be taken.
"It would be inappropriate to comment further until the matter has been given full consideration."
A similar case in 2012 saw a judge rule Devon County Council had acted unlawfully in the way it set its fees.
A group of about 100 owners took legal action, saying the council did not properly consider the impact on vulnerable residents.
In that case, the judge ordered that the council pay a third of the complainants' costs, amounting to about £220,000.