India's top court has struck down a colonial-era law that makes homosexual acts punishable by up to 10 years in prison — a landmark judgment that activists hope will improve gay rights in the country.

Thursday's Supreme Court ruling followed a petition filed by five engineers who challenged the law, saying they were living in fear of being harassed and prosecuted by police.

A five-judge panel was unanimous in its decision to end Section 377 of the law, which prohibits sex "against the order of nature."

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."

In 2009, a New Delhi High Court declared Section 377 unconstitutional but the Supreme Court said amending or repealing the law should be left to Parliament.

However, the government left it to the court to decide the validity of the law dealing with consensual sexual acts between two adults.

Gay sex is considered taboo by many in socially conservative India but LGBT activists had been hopeful of a positive judgment after the court's hearings on the matter in July.

An activist reacts after Thursday's court ruling. DIVYAKANT SOLANKI / EPA

Over the past decade, gays have gained a degree of acceptance, 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.

FOLLOW NBC OUT ON TWITTER, FACEBOOK AND INSTAGRAM