A group of disabled people have lost a court challenge to cuts in social housing benefit for residents with spare bedrooms in England, Wales and Scotland.
The High Court said the policy, dubbed a "bedroom tax" by critics, was not unlawfully discriminatory.
But it criticised the government for failing to follow a 2012 ruling that said housing benefit should not be cut where disabled children were involved.
The group said they would appeal.
Since April, people deemed to have one spare bedroom have had their housing benefit reduced by 14% while those with two or more spare bedrooms have seen reductions of 25%.
Lawyers for 10 families, which include disabled adults or children, challenged the changes during a three-day hearing in May.
Their lawyers argued the benefit cuts hit them disproportionately hard and were therefore discriminatory. Some argued that the additional bedrooms were needed for medical equipment or, in the case of some of the children, because behavioural problems made it impossible to share a room.
The High Court ruled that applying the cap to disabled people was based on "a reasonable foundation" and its effects had been "properly considered".
It said, however, said the government had been too slow to introduce new regulations prohibiting reductions in housing benefit where an extra bedroom was required for disabled children who were unable to share.
Judge Lord Justice Laws said the Department for Work and Pensions was obliged to follow an appeal court ruling and must now do so "very speedily".
The government said the new regulations would be introduced this autumn.
It also said it had already provided £150m to councils to make discretionary payments to those affected by its changes to welfare payments, and announced that it would bolster the fund for those affected by housing benefit changes by £35m.
Richard Stein, of law firm Leigh Day, which is representing two of the families, said his clients were "bitterly disappointed with today's decision, but they are not defeated".
He said: "The government's attempts to pass the buck to local authorities to deal with the unfairness and discrimination of the bedroom tax using discretionary housing payments is not acceptable."
A statement responding to the ruling on the firm's website added: "The court accepted that [the benefits changes] are discriminatory, but decided that the discrimination was justified and therefore lawful."
Shadow work and pensions minister Stephen Timms said: "David Cameron's hated bedroom tax combines incompetence with cruelty.
"The policy is a shambles and there is now a real risk that it will end up costing more than it saves."
But Deputy Prime Minister Nick Clegg said ministers were trying to make the system fairer by helping the two million households on the social housing waiting list.
It was also important that the same rules on housing benefit should be applied to social housing as to private rentals, he told BBC Radio 5 live.
The government, which hopes to save about £500m annually through the move as part of its deficit reduction strategy, say taxpayers should not be subsidising people with larger homes than necessary.
A statement from the Department for Work and Pensions (DWP) added: "We are pleased to learn that the court has found in our favour and agreed that we have fulfilled our equality duties to disabled people.
"Reform of housing benefit in the social sector is essential, so the taxpayer does not pay for people's extra bedrooms."
About 660,000 working-age social housing households judged to have spare bedrooms have lost an average of £14 per week since their benefit was cut at the beginning of April.
The DWP estimated that 420,000 disabled people were among those affected.
The claimants had mounted their legal challenge on three grounds - whether the benefits changes were lawful under the European Convention on Human Rights and the Equality Act, and whether the government had followed the correct procedures when telling councils how to curb benefits payments.
They also argued that the £25m set aside in the local authority discretionary fund for disabled people affected by the benefit cuts was insufficient.
One of the claimants, Charlotte Carmichael, who has spina bifida and sleeps in a hospital bed which, she argues, her husband and full-time carer cannot share, told the BBC said the ruling was an "absolute travesty of justice"
Mr Carmichael said his family had benefited from the discretionary fund, but added: "We've only got it for another few weeks, and then it's run out.
"There's nothing more in the pot from sources I've talked to, so we're going to be back to square one, and we can't afford it, the way we are, to lose £50 a month - well, £60 really because of the council tax changes as well."
Richard Hawkes, chief executive of the disability charity Scope, said: "The government has repeatedly referred to a discretionary fund to support those hit by this cut. But we know that this money is not getting to disabled people.
"The fact is that in 2013, disabled people are struggling to make ends meet. Life costs more if you're disabled but living costs are spiralling."
Housing charity Shelter's chief executive Campbell Robb said: "This ruling is devastating news for disabled adults and families with disabled or vulnerable children, who'll be put at real risk of homelessness for having a bedroom they just can't do without.
"As a result of today's ruling, we're really concerned that these families will now face a real struggle to meet their rent and may end up losing their home."