India's Supreme Court has struck down a 2009 lower court decision to decriminalise homosexuality, dealing a blow to gay activists who have fought for years for the chance to live openly in India's deeply conservative society.
The judges said only lawmakers and not the courts could change a colonial-era law criminalising homosexuality.
The lesbian, gay, bisexual and transgender community across India reacted to the surprise decision with defiance.
"We cannot be forced back into the closet. We are not backing off from our fight against discrimination," said Gautam Bhan, an activist who had petitioned the court.
After the ruling, dozens of activists outside the court began crying and hugging each other in consolation.
"This is a very sad day for us, we are back to square one in our fight for the democratic rights of the gay community," said Ashok Row Kavi of the activist group Humsafar Trust.
Lawyers and supporters of gays, lesbians and transsexuals vowed to continue pressing for the removal of the law, which they say encourages discrimination, even if it is rarely invoked by prosecutors.
"We feel very let down," said lawyer Anand Grover, who had argued the case on behalf of the advocacy group NAZ Foundation. "But our fight is not over and we will continue to fight for the constitutional right."
He said the foundation would ask for the Supreme Court's decision to be reviewed.
The law, dating back to the 1860s, when Britain ruled over South Asia, states that "whoever voluntarily has carnal intercourse against the order of nature with any man, woman or animal" can be punished by up to 10 years in prison.
The 2009 New Delhi High Court ruling, which said the law violated fundamental human rights, infuriated conservatives and religious groups who say homosexuality represents a threat to traditional Indian culture.
In a rare alliance, the groups - including the All India Muslim Law Board, Christian groups and Hindu spiritual leaders - argued that gay sex is unnatural and that India should maintain the law.
Amod Kanth, head of the Prayas organization for children's welfare, one of India's largest civic groups, cheered the ruling and said banning homosexuality is key to ensuring children's normal development and protecting their rights to family.
"Only a man and a woman constitute a family and contribute for the holistic development of a child, which is not possible without a father and a mother," Kanth told the Press Trust of India news agency.
Activists have long argued that the law encourages discrimination and leaves gays, lesbians and bisexuals vulnerable to police harassment or demands for bribes. In a country where arranged marriage is still largely the norm, many gays hide their sexual orientation from friends and relatives.
Acceptance is slowly growing, though, particularly in big cities such as New Delhi and Mumbai. In the last few years, activists have staged large gay pride parades featuring rainbow-coloured flags and banners, joyful songs and dancing through the streets.
The government, meanwhile, has begun acknowledging India's transgender - or hijra - community, the origins of which go back millennia to a time when transsexuals, eunuchs and gays held a special place in society backed by Hindu myths of their power to grant fertility.
In 2009, the government allowed them to register to vote as "others," rather than as men or women. And in 2010, a new "third gender" category was added to the national census.
Law Minister Kapil Sibal said little about the recent verdict beyond agreeing that the "legislature is the final arbiter of what law should be".
If the issue comes up in Parliament, he said, "we will take it up".