A five-judge bench in the Supreme Court was unanimous in overturning the ban. But the ruling could face a legal challenge from groups that say gay sex erodes traditional values of the country.
Gay sex is considered taboo by many in socially conservative India, as well as in neighbouring Bangladesh, Sri Lanka and Pakistan. It was reinstated as a criminal offence in India in 2013, punishable up to 10 years in prison, after four years of decriminalisation.
In 2009, Delhi high court had declared Section 377 unconstitutional, but that decision was overturned in a ruling by three SC justices in 2013 on the grounds that amending or repealing the law should be left to Parliament. But lawmakers failed to take action and in July the government told the apex court to give a ruling in the case.
Over the past decade, gays have gained a degree of acceptance in the country, especially in big cities. Some high-profile Bollywood films have also dealt with gay issues lately. Still, being gay is seen as shameful in much of the country.
(With agencies input)