New Delhi (CNN) India's Supreme Court has struck down a colonial-era law criminalizing consensual gay sex, overturning more than 150 years of anti-LGBT legislation.

The court announced the landmark verdict in Delhi on Thursday, as jubilant crowds cheered and rights activists hugged one another, overcome with emotion.

Section 377, an archaic law imposed during British rule that penalized intercourse "against the order of nature," had carried a maximum sentence of life imprisonment.

The decision to repeal the law is a major victory for India's LGBT activists and supporters after years of determined struggle.

"I can't even explain how I am feeling right now. The long battle has been won. Finally we have been recognized by this country," said Bismaya Kumar Raula, wiping away tears outside the court.

Others gathered said that, while they had anticipated a positive outcome, the result still came as a shock.

"It's an emotional day for me. It's a mix of feelings, it's been a long fight," said rights campaigner Rituparna Borah. "There was not enough media or society support earlier but we have it now. People will not be seen as criminals anymore."

Though the law was rarely enforced in full, lawyers argued that it helped perpetuate a culture of fear and repression within the LGBT community.

A change in legislation will "create a space of freedom where you can start expecting justice," Danish Sheikh, a law professor at Jindal Global Law School and LGBT advocate, told CNN.

Indian LGBT activists in Mumbai react to the news that the Supreme Court has struck down Section 377.

Long battle

Thursday's historic ruling is the culmination of a lengthy and often fraught legal battle for equality in a country where homosexuality remains taboo.

In 2009, the Delhi High Court ruled that the ban on consensual gay sex violated fundamental rights. The decision, which only applied to the Delhi region, was quickly overruled by the Supreme Court in 2013 , following a petition launched by a loose coalition of Christian, Hindu and Muslim groups.

In its 2013 ruling, the Supreme Court said that only a "minuscule fraction of the country's population constitute lesbians, gays, bisexuals or transgenders" and it was therefore "legally unsustainable" to repeal the act.

During the latest hearings, lawyers representing more than a dozen gay and lesbian Indians questioned the constitutional basis of that earlier ruling.

"It was a wrong judgment. It was not legal and it was based wrongly on the tenets of the constitution," said Colin Gonsalves, one of the lawyers representing the current group of petitioners.

That case was strengthened last year, when the Supreme Court moved to uphold the constitutional right to privacy

The ruling, which declared sexual orientation to be an "essential attribute of privacy," helped galvanize campaigners.

"Last year's ruling eviscerated the 2013 judgment," said Gonsalves. "There is no issue now. There is not much left to argue," he added.

What a historic day for the country! 🏳️‍🌈 #Section377 pic.twitter.com/Xx8C13wEap — Anna Isaac (@anna_isaac) September 6, 2018

Opposition to moves to overturn Section 377 had rested predominately on religious and moral objections. In an interview earlier this year, lawmaker Subramanian Swamy, a prominent member of the ruling Bharatiya Janata Party (BJP), described the legalization of gay sex as a "danger to national security" and "against Hindutva."

Hinduism has traditionally maintained a flexible, non-prescriptive view of sexuality. However, in recent years hardline Hindu groups have taken a more conservative approach.

In the run up to the judgment, the BJP refrained from taking a public stand, deferring instead to the court.

Dehumanizing colonial law

Out of the estimated 48 former British colonies that criminalize homosexuality, 30 still have laws based on the original colonial anti-LGBT legislation, according to Lucas Mendos, co-author of the 2017 International LGBTI Association "State-Sponsored Homophobia" report.

In the case of India, the original British law had remained in place more or less unchanged since it was introduced by British colonizers in the 1860s.

According to India's National Record Bureau, more than 2,100 cases were registered under the law in 2016 . India did not maintain a separate database of prosecution under section 377 until 2014.

Arif Jafar, one of the current group of petitioners whose case the Supreme Court ruled on, was arrested in 2001 under Section 377 and spent 49 days in jail.

Supporters in Mumbai react to the Supreme Court ruling that gay sex is no longer a criminal offense.

Jafar now runs an informal support group in the northern state of Uttar Pradesh. The group, named "Trust," provides counseling, support and sexual health services to gay and transgender persons.

In his petition, Jafar described the experience as dehumanizing and a violation of his fundamental rights. He also alleged that he was beaten and humiliated every day because of his sexuality.

Campaigners in India pointed out that the law didn't only trap members of the LGBT community in the closet, it also invited other forms of discrimination, providing a cover for blackmail and harassment.

Members of India's LGBT community dance in celebration after the ruling was announced in Bangalore on Thursday.

"The constant fear of 377 we have felt will not be there for the coming generation," said Yashwinder Singh, of Mumbai-based LGBT rights group The Humsafar Trust.

"Laws getting passed is one thing but changing the society is a big challenge," said Singh of the court's decision, Thursday.

"Our work has started multifold now. We have to go and talk to people and change their mindset so that they accept every human as one."

We join the people of India & the LGBTQIA+ community in their victory over prejudice. We welcome the progressive & decisive verdict from the Supreme Court & hope this is the beginning of a more equal & inclusive society. #Section377 pic.twitter.com/Fh65vOn7h9 — Congress (@INCIndia) September 6, 2018

Following the announcement Thursday, the Congress Party, the country's main opposition, posted a message of congratulations on social media, welcoming the "progressive and decisive verdict" from the Supreme Court.

As supporters celebrate the decision, activists will now be shifting focus to the broader issue of equality.

People celebrate the decision in Bangalore on September 6.

"The next step is to start looking at issues of rights. Right now, it is just decriminalizing," Anjali Gopalan, founder of the Naz Foundation, which has spearheaded the fight against Section 377, told CNN.

"The right that every citizen of the country should have access to and should not be taken for granted. Like the right to marry, the right to adopt, the right to inherit. Things that no one questions and that are clearly denied to a certain section of citizens."