Members of India's lesbian, gay, bisexual and transgender community vowed to use the historic ruling to push for greater rights including same-sex marriage in the South Asian nation of 1.25 billion people.
"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.
"History owes an apology to the members of this community and their families, for the delay in providing redressal for the ignominy and ostracism that they have suffered through the centuries," added the ruling.
Source: AAP
India is now one of more than 120 countries to have effectively decriminalised homosexuality. The ruling puts pressure on other South Asian nations which still take a hard line on gay rights.
Indian religious groups have fiercely opposed any liberalisation of sexual morality.
While LGBT groups shed tears and celebrated, the conservative government made no immediate comment on the ruling. The government had opposed action against Section 377 but finally said it would give in to the "wisdom" of the top court.
"It was a law that propagated homophobia," said Keshav Suri, one of the petitioners against Section 377, who organised a Bollywood-style dance show and champagne party at his family's luxury Delhi hotel to celebrate the court victory.
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.
Source: AAP
Tears and chocolate
Members of the LGBT community hugged each other and cried outside the Supreme Court in New Delhi as news of the verdict spread.
In Chennai, gay activists handed out chocolate. "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 to watch on television.
Activists had been fighting the ban since the 1990s, suffering several court reversals 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, seven people were convicted on charges of "unnatural offences" and 16 acquitted in 2016.
Source: AAP
The United Nations hailed the ruling as "a day when respect and dignity was finally restored in India for lesbian, gay, bisexual, transgender and intersex people."
Michel Sidibé, executive director of UN AIDS, added: "I applaud the brave activists, civil society organizations and community groups that have fought long and hard for this injustice to be reversed."
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.
Many activists like Suri say that gay marriage and equal inheritance rights for gay couples will be the ultimate equality prize. But government lawyers warned the Supreme Court judges against changing other parts of the law.
"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."
Prince Manvendra Singh Gohil, a campaigner and only openly gay member of an Indian royal family, said the ruling had "paved way for a larger social change in the society.
"For the first time since independence the gay community in the country is experiencing freedom in the real sense," Gohil told AFP.
"Now the bigger task is to bring about acceptance in society. We need a lot of advocacy to spread awareness on the issue that gay people have equal rights like any other individual in India."
New Delhi choreographer Mandeep Raikhy, who has used the performances of his dance troupe to highlight the experience of gays, was more cautious.
"I don't want to sound pessimistic but I don't think we will see gay marriage in my lifetime," he said.