India’s supreme court has struck down a law from the colonial era that made gay sex punishable by up to 10 years in prison.

In a unanimous decision, five Supreme Court justices ruled the law was a weapon used to harass members of the 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.”

India Gay Rights
An activist wears a badge protesting against section 377 of the law (Rafiq Maqbool/AP)

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 gay people living in fear of being harassed and prosecuted by police.

Arvind Datar, the attorney for the petitioners, argued in 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.

India Gay Rights
A gay rights activist celebrates after the country’s top court struck down the colonial-era law (Altaf Qadri/AP)

However, 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, gay people 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 but being gay is still 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.