Updated

India's top court on Thursday struck down a colonial-era law that made homosexual acts punishable by up to 10 years in prison, a landmark victory for gay rights in the world's largest democracy.

In a unanimous decision, five Supreme Court justices ruled that the law was a weapon used to harass members of India's gay community and resulted in discrimination. After the ruling, opponents of the law danced and waved flags outside the court.

"We feel as equal citizens now," activist Shashi Bhushan said. "What happens in our bedroom is left to us."

The law — known as Section 377 — held that intercourse between members of the same sex was against the order of nature. The five petitioners who challenged the law said it was discriminatory and led to gays living in fear of being harassed and prosecuted by police.

Arvind Datar, the attorney for the petitioners, argued in the court that the penal provision was unconstitutional because it provides for the prosecution and sentencing of consenting adults.

A New Delhi High Court in 2009 declared Section 377 unconstitutional, but that decision was overturned in a ruling by three Supreme Court 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 Supreme Court to give a ruling in the case.

Over the past decade, gays have gained a degree of acceptance in parts of deeply conservative India, especially in big cities. Some high-profile Bollywood films have dealt with gay issues. Still, being gay is seen as shameful in much of the country.

Karan Johar, a Bollywood producer and director, said Thursday's verdict was history in the making.

"So proud today! Decriminalizing homosexuality and abolishing section 377 is a huge thumb up for humanity and equal rights! The country gets its oxygen back!" he wrote on Twitter.