Image copyright GARY LIM Image caption Gay couple Gary Lim (L) and Kenneth Chee (R) had mounted one of the two rejected legal challenges

Human rights groups have condemned a Singapore court's decision that a law banning gay sex is constitutional.

The Court of Appeal on Wednesday rejected two legal challenges arguing that the law, Section 377A, infringes on gay citizens' rights.

Under Section 377A, men who engage in "gross indecency" privately or publicly can be jailed for up to two years.

Singapore, which largely remains conservative, has seen intense debate in recent years over gay rights.

Human Rights Watch called the decision "a major setback for equal rights", adding that it "tramples upon basic rights to privacy, equality and non-discrimination".

On Thursday, 14 local rights groups released a statement saying the court had missed an opportunity to show that Singapore was "a truly accepting, open and inclusive society".

The groups said Section 377A "gives carte blanche for discrimination and reinforces prejudice".

"To be viewed as equal in the eyes of the law... is a right to which every Singaporean should be entitled, and not denied on the basis of whom they love," they added.

Jean Chong, spokesman for lesbian group Sayoni, told the BBC that the ruling effectively made homosexual, bisexual and transgender Singaporeans "second-class citizens".

Image copyright AFP Image caption Gay rights groups have held the annual Pink Dot rally in the heart of Singapore since 2009

Government leaders have pledged not to enforce Section 377A, first introduced in 1938 by British colonial rulers. But they have also refused to remove it, saying it reflects the conservative mores of Singapore society.

Lawyers involved in the legal challenges, mounted separately by a gay couple and a gay man, argued that the law went against the constitution guaranteeing "life and liberty" and equal protection.

But the court rejected these claims, and said it was up to legislators to decide on the law.

Though surveys have shown most Singaporeans do not accept homosexuality, there is widespread tolerance. Since 2009 rights groups have held an annual rally known as Pink Dot, which this year drew its largest-ever crowd of 26,000.

But conservatives have pushed back against gay activism and campaigned vigorously for Section 377A to remain.

In July, library authorities withdrew copies of two children's books featuring same-sex couples including gay penguins, prompting a national debate. The books, slated for pulping, were eventually placed in the adult section.