“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 and cross-dressers is hijra (eunuch).
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.
So far, they have been forced to write either male or female as their gender.
“Transgenders are also citizens of India” and they must be “provided equal opportunity to grow”, the court said in its order on Tuesday.
“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.
The court said the government must also work to raise awareness about the third gender and make sure that they have access to medical care and other facilities like toilets.