The Court of Appeal ruled that Allerdale Council in Cumbria and the London borough of Waltham Forest were entitled to rely on their own "abuse of power" to avoid having to pay back debts to Credit Suisse.
The bank had argued that it would fly in the face of justice and common sense to allow the authorities to get away scot-free because of their illegal actions.
But the court held that the contracts at the centre of the two cases, under which the councils guaranteed loans made to development companies they had set up to get round borrowing limits imposed by central government, were invalid and therefore unenforceable.
The bank was granted leave to appeal to the House of Lords. Other cases are said to depend on the outcome.
In 1986, Allerdale had put pounds 6m into an ultimately disastrous time-share and leisure pool project in Keswick . The council's statutory borrowing limit was pounds 3.6m.
When the scheme collapsed under massive debts, the bank sued for its money, but the council relied on its own breach of public duty to "renege on its private law obligations", said Lord Justice Peter Gibson, sitting with Lords Justices Neill and Hobhouse.
Although the bank may have expected a loan to a governmental body be repaid, it had entered into the contract with open eyes.
The court ruled that neither the establishment of a company nor the giving of a guarantee fell within the express or implied powers of the council.
In 1988, Waltham Forest had guaranteed an pounds 11m loan to a company set up in a "laudable" attempt to provide housing for the borough's homeless and raise money for a charitable housing trust in the face of stringent financial controls imposed by central government.
The council indemnified the company against all losses arising out of the project.
The scheme went bust with the collapse of the property market in about 1990.
Lord Justice Neill said that, although the purpose of the scheme was to alleviate hardship and make the best provision possible for the accommodation of homeless people, it had been a nullity from the outset because the council had no power to give the guarantee or indemnity.
"It may be that later similar schemes have or will become within the powers of local authorities, but we have to look at the position in 1988," he said.
The judges dismissed the bank's appeal against a High Court ruling that Allerdale was not legally bound to repay the debt, and allowed Waltham Forest's appeal against an order requiring it to pay up.Reuse content