NEW DELHI — The Indian Supreme Court reinstated on Wednesday a colonial-era law banning gay sex, ruling that it had been struck down improperly by a lower court.

The 1861 law, which imposes a 10-year sentence for “carnal intercourse against the order of nature with man, woman or animal,” was ruled unconstitutional in a 2009 decision. But the Supreme Court held that only Parliament had the power to change that law.

There is almost no chance that Parliament will act where the Supreme Court did not, advocates and opponents of the law agreed. With the Bharatiya Janata Party, a conservative Hindu nationalist group, appearing in ascendancy before national elections in the spring, the prospect of any legislative change in the next few years is highly unlikely, analysts said.

Anjali Gopalan, founder of a charity that sued to overturn the 1861 law, said she was shocked by the ruling.