A dying and homeless Portuguese man who was refused accommodation and was being repatriated to Portugal by a London council has won his High Court case.
Kensington and Chelsea Council's move to send Adalberto Jesus de Almeida back would be "inhuman", the court ruled.
The council argued its refusal to offer him help since 2010 was "justified" due to the "scarce resources".
Mr de Almeida suffers from HIV/Aids and skin cancer and has been told he has less than a year to live.
Mr de Almeida first came to live in the UK lawfully between 1998 and 2002, before going to Spain and then returned to the UK in 2008. He moved to London a year later to work.
Mr de Almeida, who contracted HIV/Aids before coming to the UK through taking drugs, was evicted from his private rented accommodation when he could not afford the rent after becoming too ill to work, the court heard.
He was supported by friends for a time before moving to a hostel in Ladbroke Grove, west London, and sought benefits.
The council said its decision to refuse accommodation and assistance to the homeless man was "justified and proportionate" in the light of "other demands on its scarce resources".
But Mrs Justice Lang, said it would be "inhuman treatment to send him to an undignified and distressing end in Portugal" and the move was incompatible with Mr de Almeida's Article 3 right not to be subjected to inhuman and degrading treatment under the European Convention on Human Rights.
She said he would find it difficult to support himself if he was sent back and would be "parted from his existing support network of friends and healthcare professionals" and the move would also breach his Article 8 right to a private and family life under the Convention rights.
Mrs Justice Lang accepted the council was acting for "the economic well-being of the country", but added: "However, the claimant has a limited life expectancy and so the cost to the public purse is not open-ended."