Gay rights activists hold placards during a protest meeting in Bangalore, India, Wednesday, after the country’s top Indian court ruled that a colonial-era law criminalizing homosexuality will remain in effect in India.

NEW DELHI — India’s Supreme Court struck down a 2009 lower court decision to decriminalize homosexual conduct, dealing a blow Wednesday to gay activists who have fought for years for the chance to live openly in India’s deeply conservative society.

The judges said only lawmakers and not the courts could change a colonial-era law that bans homosexual acts and makes them punishable by up to a decade in prison.

The lesbian, gay, bisexual and transgender community across India reacted to the surprise decision with defiance.

“We cannot be forced back into the closet. We are not backing off from our fight against discrimination,” said Gautam Bhan, an activist who had petitioned the court.

After the ruling, dozens of activists outside the court began crying and hugging each other in consolation.

“This is a very sad day for us, we are back to square one in our fight for the democratic rights of the gay community,” said Ashok Row Kavi of the activist group Humsafar Trust.

Lawyers and supporters of gays, lesbians and transsexuals vowed to continue pressing for the removal of the law, which they say encourages discrimination, even if it is rarely invoked by prosecutors.

“We feel very let down,” said lawyer Anand Grover, who had argued the case on behalf of the advocacy group NAZ Foundation. “But our fight is not over and we will continue to fight for the constitutional right.”

He said the foundation would ask for the Supreme Court’s decision to be reviewed.

According to international human-rights groups, more than 70 countries around the world have laws criminalizing homosexual conduct, with India by far the most populous. Some other countries, while not explicitly outlawing gay sex, have measures that restrict gay-rights activities, such as Russia’s recently enacted law prohibiting “gay propaganda.”

Efforts to repeal colonial-era anti-sodomy laws have failed to gain much momentum in Africa and Asia, but there have been notable recent gay-rights gains in Latin America, where same-sex marriage or civil unions have been legalized in Argentina, Uruguay, Brazil and parts of Mexico.

The largest gay-rights group in the United States — the Human Rights Campaign — described the Indian court ruling as a “disturbing step backward.”

“It is incomprehensible that a court of law would take the side of discrimination against LGBT citizens,” said the group’s chief foundation officer, Jeff Krehely. “Criminalizing LGBT relationships leads to dangerous situations, not just for committed couples, but also for LGBT youth, who today received a deeply harmful message that they are less than equal.”

The United States expressed concern about the Indian Supreme Court decision, although it wasn’t immediately clear if Washington had directly raised the issue with Indian government officials.

“We oppose all actions that criminalize consensual sex conducts between adults,” State Department spokeswoman Jen Psaki told reporters in Washington. “We call on all governments to advance equality for LGBT individuals around the world.”

But the court ruling was welcomed by a conservative U.S. legal advocacy group, Alliance Defending Freedom.

“The India Supreme Court has ruled in the interest of the health of its society rather than the interests of activist groups trying to use the court to do their bidding,” said the group’s chief counsel, Benjamin Bull.

The law in question, dating back to the 1860s when Britain ruled over South Asia, states that “whoever voluntarily has carnal intercourse against the order of nature with any man, woman or animal” can be punished by up to 10 years behind bars.