India’s Supreme Court on Thursday struck down a colonial-era ban on gay sex at the center of years of legal battles.

“The law had become a weapon for harassment for the LGBT community,” Chief Justice Dipak Misra said as he announced the landmark verdict.

Section 377 of the Indian penal code, enacted by British rulers in 1861, banned “carnal intercourse against the order of nature.”

Activists had been fighting the ban since the 1990s, suffering several court reverses before Thursday’s verdict which sparked celebrations among lesbian, gay, bisexual and transgender groups across the vast South Asian nation.