MPs in Singapore have legalised oral and anal sex for adult heterosexuals but kept the ban on gay sex, saying that the bill was what citizens in the conservative island state wanted.

The reforms, which were passed on Tuesday, represent the most extensive revision of the conservative city state's penal code in more than two decades.

The changes mean oral and anal sex between consenting heterosexual adults is no longer an offense but section 377A, which deals with oral and anal sex between consenting men, remains in force.

The "gross indecency" offence carries a maximum penalty of two years in jail although it is rarely punished in Singapore, which has a thriving gay community.

"Singapore is basically a conservative society," the prime minister, Lee Hsien Loong, told MPs before the vote. "The family is the basic building block of this society. And by family in Singapore we mean one man, one woman, marrying, having children and bringing up children within that framework of a stable family unit."

Mr Lee also warned gay rights activists against forcing the issue, which he said had become an emotional and divisive matter that was best left to evolve gradually.

"The more gay activists push this agenda, the stronger will be the push-back from conservative forces," Mr Lee said. "The result will be counterproductive because it's going to lead to less space for the gay community in Singapore."

A petition for homosexual sex to be legalised was signed by 2,341 people over three days. Supporters said the government's plan to legalise only oral and anal sex for heterosexual adults was unjust.

Stuart Koe, one of the petitioners and chief executive of the Hong Kong-based group Fridae.com, an online community of gays and lesbians in Asia, said: "We're obviously very disappointed ... but the petitioners feel that the way moving forward probably would not be to continue politicising or lobbying directly for a repeal, but working with society and within the community to try to foster a greater understanding."

Other amendments included a ban on necrophilia, tougher penalties for sex with minors under 14, and penalties for men who rape their wives, in some instances.