India's Supreme Court on Thursday struck down a ban on gay sex after a decades-old campaign against a colonial-era law used to hold back LGBT rights.

Members of lesbian, gay, bisexual and transgender groups held tearful celebrations in cities across the South Asian nation of 1.25 billion people as the historic verdict was read out.

"The law had become a weapon for harassment for the LGBT community," said chief justice Dipak Misra as he quashed the cornerstone of Section 377, a law introduced by British rulers in 1861.

"Any discrimination on the basis of sexuality amounts to a violation of fundamental rights," he added in the ruling, which added India to a list of more than 120 countries where homosexuality is decriminalised.

While India's law only legalises sexual acts between adults, gay activists have hailed the verdict as a major boost in the deeply conservative country where religious groups have fiercely opposed any liberalisation of sexual morality.

Activists had been fighting the ban since the 1990s, suffering several court reverses before Thursday's verdict.

The Delhi High Court decriminalised gay sex in 2009, but the Supreme Court reinstated the ban in 2014 after an appeal by religious leaders.

According to official data, 2,187 cases under Section 377 were registered in 2016 under the category of "unnatural offences". Seven people were convicted and 16 acquitted.

"It was a law that propagated homophobia," said Keshav Suri, one of the petitioners against Section 377, who organised a dance show at his family's luxury Delhi hotel to celebrate the court victory.

"In rural areas it is a harassment tool, used by cops, used by authorities for extortion for glorifying rape and molestation," Suri told AFP in an interview ahead of the verdict.

Many Indian gay professionals have moved to Canada and Europe where they are more accepted, added the businessman who married his partner in Paris this year.

India's conservative government had opposed ending Section 377 but said ahead of the hearing that it would leave the decision to the "wisdom" of the Supreme Court .

It had warned, however, that judges should not change other aspects of Indian law, such as the right to marriage.

'Long battle'

Members of the LGBT community hugged each other and cried outside the Supreme Court in New Delhi as news of the verdict spread.

"I am speechless! It's taken a long time to come but finally I can say I am free and I have equal rights as others," said Rama Vij, a college student in Kolkata who gathered with others watching on television.

Despite the pressure on the LGBT community, India has quietly made some strides in sexual rights in recent years.

A transgender judge, Joyita Mondal Mahi, presides over courts in West Bengal state, Indian passports now state whether a holder is "male", "female" or "other", and the city of Raigarh, with 139,000 people, has a transgender mayor.

Suri's hotels are known for their gay-friendly discos and more professionals are coming out to challenge the Indian establishment.

Many say that gay marriage and equal rights in inheritance and other areas must be the ultimate prize, but they acknowledge that change will not be swift.

"This is the first step of the history of a lot of other countries that first decriminalised gay sex, allowed civil unions and then marriage," said Suri.

"It is a long battle to equal rights but I am sure we will get there eventually."

New Delhi choreographer Mandeep Raikhy, who has used the performances of his dance troupe to highlight the experience of gays, was even more cautious.

"I don't want to sound pessimistic but I don't think we will see gay marriage in my lifetime," he said.