In a historic verdict, India's Supreme Court ruled that gay sex is no longer a criminal offence in the country.
The ruling overturns a 2013 judgement that upheld a colonial-era law, known as section 377, under which gay sex is categorised as an "unnatural offence".
It is one of the world's oldest laws criminalising gay sex, and India had been reluctant to overturn it.
Campaigners outside the court cheered and some broke into tears as the ruling was handed down.
"Criminalising carnal intercourse is irrational, arbitrary and manifestly unconstitutional," Chief Justice Dipak Misra said while reading out his judgement.
Another judge, Indu Malhotra, said she believed "history owes an apology" to LGBT people for ostracising them.
The law was first struck down by the Delhi high court in 2009, but it was reinstated by the Supreme Court in 2013, after several political, social and religious groups petitioned for its restoration.
But in 2016, the court decided to revisit that ruling after campaigners submitted what is known as a "curative petition", which is a formal request to review an earlier court order perceived as a "miscarriage of justice".
Even though public opinion in India's biggest cities has been in favour of scrapping the law, there remains strong opposition among religious groups and in conservative rural communities.
But this ruling from the top court is now the final say in the matter as it cannot be challenged any further. As such, it represents a huge victory for India's LGBT community.
What is section 377?
It is a 157-year-old colonial-era law which criminalises certain sexual acts as "unnatural offences" that are punishable by a 10-year jail term.
The law punishes, in its own words, "carnal intercourse against the order of nature with any man, woman or animal".
While the statute criminalises all anal and oral sex, it has largely affected same-sex relationships.
India's gay and transgender communities have fought long and hard to strike down the law.
Human rights groups have said police have used the statute to harass and abuse members of the LGBT community.
Equal rights activists have also argued that the very existence of such a law was proof of discrimination based on sexual orientation.
Why is this verdict so significant?
India's gay and transgender communities have fought long and hard to strike down section 377, as the law is known.
"How strongly must we love knowing we are unconvicted felons under Section 377? My Lords, this is love that must be constitutionally recognized, and not just sexual acts," Menaka Guruswamy, the lawyer for the petitioners, had told the Supreme Court in July when it began hearing the case.
But it is still too early to say what this can translate to in the longer term.
The judges explicitly said that they only ruled on the constitutional validity of section 377 and were not looking at it in terms of other rights such as those related to marriage or inheritance.
'Recognising everyone's right to love'
Geeta Pandey, BBC News, Delhi
Even though it was rarely invoked when it involved consenting adults, Section 377 could be - and was sometimes - used as a tool for harassment. It is not surprising then that campaigners are describing the verdict as a "new dawn for personal liberty".
But in a largely conservative India, where leaders of all religions have consistently opposed gay sex, it will still be a while before attitudes change and the community finds full acceptance.
But laws almost always play an important role in changing mindsets, and by recognising the community's right to love, the Supreme Court has restored the dignity denied to them for a very very long time.