“This ruling is hugely significant,” said Meenakshi Ganguly, the South Asia director for Human Rights Watch. With restrictions on gay rights toppling in country after country, the ruling in India, the world’s second-most-populous nation, may encourage still more nations to act, she said.

Still, however historic the ruling of the court, considered a liberal counterweight to the conservative politics sweeping India, gay people here know that their landscape remains treacherous. Changing a law is one thing — changing deeply held mind-sets another. And few suggested that other major victories, like same-sex marriage, were on the near horizon.

Many Indians are extremely socially conservative, going to great lengths to arrange marriages with the right families, of the right castes. Loved ones who try to rebel are often ostracized. Countless gays have been shunned by their parents and persecuted by society.

Much of this may also be true in other parts of the world. But what made India stand out from most — at least until Thursday — was its application of an anachronistic law drawn up by British colonizers during the Victorian era and kept on the books for 150 years.

The law banned sex considered “against the order of nature,” and thousands of people were prosecuted under it. But for gays in India, prison was only one of the risks. The law was often used as a cudgel to intimidate, blackmail and abuse.