Four months after India's Supreme Court maintained that homosexuality was a crime, its judges gave a landmark ruling Tuesday saying that the people of a third gender, neither male nor female, are now legally recognized and must have equal rights to education, jobs and driving licenses.

"Recognition of transgenders as a third gender is not a social or medical issue but a human rights issue," the court said Tuesday, and urged the government to set aside quotas in jobs and education for the fiercely independent but segregated community of eunuchs in India. The ruling said that transgendered people face discrimination in their access to public spaces like restaurants, cinemas, shops, malls and public toilets.

But ironically, the progressive ruling applies only to eunuchs – or hijras as they are called in Hindi — in India and not to gays, lesbians and bisexuals.

In many ways, expanding the rights to transgendered people is far easier than legalizing homosexuality in India. For centuries, eunuchs – called hijras in Hindi — were given a special place in Indian religious epics and parables.

"Granting rights to transgenders is more acceptable to our psyche because we find many transgender characters in our religious, cultural mythologies and literature. Some of our Hindu Gods were of third-gender, some Gods changed their gender seamlessly to perform specific roles and rituals," said Rose Venkatesan, who transitioned from being a man to a woman four years ago and is a former television host and an independent filmmaker in the southern city of Chennai. "There are temples and annual religious festivals for the transgender community."

But in modern times, the eunuch community has lived in closed and segregated communes, either feared or reviled by their neighbors. In cities, it is not uncommon for eunuchs to show up at wedding parties and celebrations of the birth of a child wearing vibrant clothing and singing and dancing, clapping their hands aggressively and demanding money in return for blessing.

In December, India's gay community suffered a bruising defeat when the Supreme Court overturned an earlier, historic lower-court ruling of 2009 that said homosexuality was not a crime. But after four years of celebrations and gay pride parades across India, the Supreme Court pushed the community back in the closet after it heard appeals filed by several religious, cultural and political groups.

The Supreme Court had upheld the British colonial-era law describing homosexuality as "against the order of nature" and said that the parliament must decide whether the Indian penal code has to be changed.

The ruling Congress party had opposed the Supreme Court rollback of gay rights at that time. And the opposition Hindu nationalist Bharatiya Janata Party, which is mounting a powerful political challenge to the Congress party in the ongoing national election, is opposed to homosexuality.

"Transgenders are also citizens of India. It is the right of every human being to choose their gender," the court's judges ruled Tuesday and asked the government to consider them a "socially and educationally backward" class, a category that is entitled to government affirmative action and welfare benefits in India. All government forms will now have a separate third box for this gender.

India's Election Commission had issued voter identity cards for the first time to transgendered people last year, by recognizing nearly 1 million people as the "other" gender.

Other countries, such as Germany, have recently began expanding rights for transgendered people, and Pakistan and Bangladesh have extended some rights to their own hijras communities in recent years. Petitioner Laya Mehndi told television reporters outside the court that the transgender group had won their basic fight for identity from being a "legal non-entity" earlier.

"Today, for the first time, I feel proud that I am an Indian," Lakshmi Narayan Tripathy, a popular transgender rights activist and one of the petitioners, told reporters. A country's progress is "dependent upon human rights of its people," she said.

Many now hope that Tuesday's ruling may push India to recognize homosexuality as well and energize the gay community for the bigger battle ahead.

Indians accept the presence of the transgender community, but they are still kept away because of the "homosexuality connotation that transgenders carry with them," Rose said. "But the language of the ruling today gives me hope."

In its 113-page ruling, the court said that transgendered people are "sidelined and treated as untouchables, forgetting the fact that the moral failure lies in the society's unwillingness to contain or embrace different gender identities and expressions, a mindset which we have to change."

A new Supreme Court bench is now examining the gay rights issue separately after the government filed a curative petition this year. ​