A victim of domestic violence and the family of a severely disabled teenager have won a ruling that the so-called ''bedroom tax'' discriminates against them.
Lord Chief Justice Lord Thomas and two other Court of Appeal judges declared the discrimination had not been "justified" by the Government.
Prime Minister David Cameron said he would study the judgment after Labour called for the "bedroom tax" to be abolished.
The judges declared that a woman referred to as "A", who lives in a council house fitted with a secure panic room to protect her from a violent ex-partner, and Paul and Sue Rutherford, who look after 15-year-old grandson Warren, had "suffered discrimination" contrary to Article 14 of the European Convention on Human Rights (ECHR).
A spokesman for the Department for Work and Pensions said it had been granted permission to appeal to the Supreme Court, adding: "We fundamentally disagree with the court's ruling on the ECHR, which directly contradicts the High Court."
Mr Rutherford, from Pembrokeshire, said: "I'm a bit lost for words. I could almost cry with happiness. Other people are going to benefit from this decision as well. That was partly why we did it."
At the Court of Appeal it was argued that there was unlawful discrimination against victims of domestic violence and children in the situation of the Rutherfords' grandson.
Lord Thomas, Lord Justice Tomlinson and Lord Justice Vos allowed the appeals in both cases on the ground that the "admitted discrimination in each case" had "not been justified by the Secretary of State".
One of the cases was brought by single mother A and concerned the effect of the policy on women living in Sanctuary Scheme homes which have been specially adapted because of risks to the women and children who live in them.
The other, brought by the Rutherfords, involved its impact on seriously disabled children who need overnight care.
The Government rejects the term ''bedroom tax'' and says the regulations remove what is in fact a ''spare room subsidy'', with the aim of encouraging people to move to smaller properties and save millions of pounds from the housing benefit bill.
Lord Thomas said the effect of the 2012 housing benefit regulations - which came into force on April 1 2013 - was to reduce housing benefit "if the accommodation in which a person lived exceeded the number of bedrooms deemed to be required as defined by a formula".
That formula was varied under Regulation B13 "which provided that an additional bedroom would be allowed for defined classes of persons".
Both A and the Rutherfords argued that they should be part of that defined class, and that their omission was unlawful discrimination under Article 14.
Lord Thomas said both cases had proceeded on the "accepted basis" that Regulation B13 "constitutes prima facie discrimination" on the grounds of sex in the case of A and disability in the Rutherford action.
He said the primary question for the court was "whether the Secretary of State was able to show that there was objective and reasonable justification for that discrimination which was not manifestly without reasonable foundation".
In A's case the Secretary of State had placed "particular reliance on the fact that A and those in her position were receiving and would receive DHPs (Discretionary Housing Payments) that meant they always had the full amount that would otherwise have been payable as housing benefit".
In the Rutherford case it was contended, said Lord Thomas, that there was "proper justification for treating the accommodation needed for carers of disabled adults and disabled children differently and in any event DHPs would be made in all appropriate cases", as had happened in Warren's case.
Judges have heard that A's former partner has raped, assaulted and threatened to kill her, but she nevertheless faced losing £11.65 a week from her benefits.
This was because her panic room was regarded as a spare room under the regulations and A was deemed to be ''under-occupying'' her home.
The DWP argued that her challenge lacked credibility because funds in the form of discretionary housing payments (DHPs) were available through local councils to people facing exceptional circumstances.
The Rutherfords care for Warren, who has a rare genetic disorder which means he is unable to walk, talk or feed himself and is doubly incontinent.
The family live in a three-bedroom bungalow adapted for his needs, with the couple in one room, Warren in another, and the third needed for carers staying overnight and to store equipment.
They launched a judicial review over the regulations, which allow for an additional bedroom if the claimant or their partner require overnight care but make no provision for children who need an overnight carer.
During Prime Minister's Questions, Mr Cameron said that "our fundamental position is that it's unfair to subsidise spare rooms in the social sector if you don't subsidise them in the private sector where people are paying housing benefit. That is a basic issue of fairness".
Shadow work and pensions secretary Owen Smith said: "This victory in the Court of Appeal is a massive blow to the Tories' bedroom tax. Surely the time has now come for the Tories to discover a conscience, listen to the courts as well as the public, and scrap the hated bedroom tax."