A decision which could see 21 libraries close in Somerset and Gloucestershire has been ruled "unlawful".
Somerset County Council wanted to withdraw funding for 11 libraries and Gloucestershire County Council wanted to stop funding 10 libraries.
At the High Court, Judge Martin McKenna said the closures did not comply with "public sector equality duties" owed to vulnerable social groups.
These include the elderly, disabled, single mothers and children.
The decision means the closure plans have been reversed.
Campaigners began the legal action after the two authorities announced plans to cut costs.
In a statement, Daniel Carey of Public Interest Lawyers, the firm representing the campaigners, said: "Today's High Court ruling sends a clear message not only to Gloucestershire and Somerset, but to every council in the country that catering for the needs of the vulnerable must be at the heart of any decision to cut important services such as libraries.
"The 'Big Society' cannot be relied upon to justify disenfranchising vulnerable individuals from the services on which they rely."
Demelza Jones, from Friends of Gloucestershire Libraries, said: "This is a real vindication for our campaign which has long said that is it unfair to remove libraries from the most disadvantaged and vulnerable members of our communities."
However the judge ruled in favour of Gloucestershire County Council on two of the three claims made against it over its duty to provide a comprehensive library service to the community.
Ken Maddock, the Conservative leader of Somerset County Council, said that he welcomed the "court's agreement that our plans would still provide a comprehensive and efficient service".
He added: "We also welcome the judge's comments that our consultation process met all requirements."
Pete Bungard, Gloucestershire County Council's chief executive, said: "The judge found we needed to do more with regards to our responsibilities under the Equalities Act.
"This is a huge disappointment as we take our duties here extremely seriously.
"With hindsight, we approached this as a transfer to the community rather than a statutory closure where a more thorough approach would have been taken."
Campaigners argued the councils had to provide a "comprehensive and efficient" library service under the 1964 Museums Act.
James Goudie QC, representing both Gloucestershire and Somerset county councils, had argued that a comprehensive service did not mean blanket coverage over a geographical area.
The councils were refused permission to appeal, but they can apply directly to the Court of Appeal in a bid to take the case further.