India's Supreme Court has recognised transgender people as a third gender, in a landmark ruling.
"It is the right of every human being to choose their gender," it said in granting rights to those who identify themselves as neither male nor female.
It ordered the government to provide transgender people with quotas in jobs and education in line with other minorities, as well as key amenities.
According to one estimate, India has about two million transgender people.
In India, a common term used to describe transgender people, transsexuals, cross-dressers, eunuchs and transvestites is hijra.
Campaigners say they live on the fringes of society, often in poverty, ostracised because of their gender identity. Most make a living by singing and dancing or by begging and prostitution.
Rights groups say they often face huge discrimination and that sometimes hospitals refuse to admit them.
They have been forced to choose either male or female as their gender in most public spheres.
"Recognition of transgenders as a third gender is not a social or medical issue but a human rights issue," Justice KS Radhakrishnan, who headed the two-judge Supreme Court bench, said in his ruling on Tuesday.
"Transgenders are also citizens of India" and they must be "provided equal opportunity to grow", the court said.
"The spirit of the Constitution is to provide equal opportunity to every citizen to grow and attain their potential, irrespective of caste, religion or gender."
The judges asked the government to treat them in line with other minorities officially categorised as "socially and economically backward", to enable them to get quotas in jobs and education.
"We are quite thrilled by the judgement," Anita Shenoy, lawyer for the petitioner National Legal Services Authority (Nalsa), told the BBC.
"The court order gives legal sanctity to the third gender. The judges said the government must make sure that they have access to medical care and other facilities like separate wards in hospitals and separate toilets," she said.
Prominent transgender activist Laxmi Narayan Tripathi, who was among the petitioners in the case, welcomed the judgement, saying the community had long suffered from discrimination and ignorance in the traditionally conservative country, reports the Agence France-Presse news agency.
"Today, for the first time I feel very proud to be an Indian," Ms Tripathi told reporters outside the court in Delhi.
In 2009, India's Election Commission took a first step by allowing transgenders to choose their gender as "other" on ballot forms.
But India is not the first country to recognise a third gender. Nepal recognised a third gender as early as in 2007 when the Supreme Court ordered the government to scrap all laws that discriminated on the basis of sexual orientation or gender identity. And last year, Bangladesh also recognised a third gender.
Tuesday's ruling comes after the Supreme Court's decision in December which criminalised gay sex by reversing a landmark 2009 Delhi High Court order which had decriminalised homosexual acts.
According to a 153-year-old colonial-era law - Section 377 of the Indian Penal Code - a same-sex relationship is an "unnatural offence" and punishable by a 10-year jail term.
Legal experts say Tuesday's judgement puts transgender people in a strange situation: on the one hand, they are now legally recognised and protected under the Constitution, but on the other hand they may be breaking the law if they have consensual gay sex.