First there was surprise, then shock, then anger. By nightfall thousands across India had taken to the streets in spontaneous protests against an unexpected supreme court decision on Wednesday reversing a judgment that had decriminalised gay sex in the country.

Activists had expected the court simply to rubber-stamp the original 2009 ruling. Now India will rejoin the more than 70 countries – mainly in Africa, the Middle East and south Asia – where homosexual relations are illegal.

The reinstatement of a 153-year-old law passed under British rule and based on 16th-century English legislation means "carnal intercourse" between consenting adults of the same sex is once more defined as "unnatural" and punishable by up to 10 years in jail.

Waving multicoloured flags and wearing black bandanas, the crowd of protesters that gathered at the Jantar Mantar, a favourite point for demonstrations in the Indian capital, Delhi, was full of young men and women.

For many the predominant emotion was disappointment. The 2009 decision of the high court in Delhi to repeal the law banning gay sex, known as section 377, was seen as a landmark in the campaign for equality in India.

"I was so disheartened by this judgment. It was supposed to be a first in a series of rights for the LGBT in India: property rights, marriage rights and so on," said Raja Bagga, a 25-year-old lawyer. "It would have been a precursor to a better, dignified life."

Few expected the legal challenge launched by conservatives – including Muslim and Christian religious associations, a rightwing politician and a retired government official turned astrologist – to succeed. The supreme court is known for its broadly progressive judgments that often order politicians or officials to respect the rights of the poor, disadvantaged or marginalised communities.

"It's a tremendous blow. It's unprecedented for a court with a long history of expanding rights to reduce dignity, not protect it," said Gautham Bhan, a prominent gay activist.

Among the supporters of the challenge was Baba Ramdev, a Hindu holy man with a mass following who has fought a long legal battle to maintain the ban on gay sex.

At a press conference following the judgment, Ramdev invited the gay community to his yoga ashram where he said he would "cure them of homosexuality", which he described as "unnatural, uncivilised, immoral, irreligious and abnormal". He said he would do so by "keeping them in a room with a heterosexual for a few days".

Tanuja Thakur, a Hindu spiritual leader, told the Guardian: "When two people of same sex indulge in a physical activity, it goes against nature. And anything unnatural is criminal in nature."

He said homosexuality was "happening because society is not doing enough spiritual practice".

The fierce debate – at least among metropolitan elites – prompted by Wednesday's judgment demonstrates how sexual relations have become a battleground in India, often revealing cultural splits between generations, between urban and rural dwellers and between those who invoke a "traditional past" contaminated by western influences and those who stress a local history of pluralism and tolerance.

Few now expect the beleaguered government, led by the Congress party, to risk limited political capital and sparse energy on a fight for gay rights.

The opposition Bharatiya Janata party, a Hindu nationalist party, has won a series of recent victories in state elections at the expense of the traditionally liberal, secular Congress, and though Indian society is changing very rapidly it remains profoundly conservative. The home minister, Sushil Kumar Shinde, said it was "not possible to legislate on anything now".

Gay rights activists say the community faces significant discrimination and police harassment, even if prosecutions for same-sex activity have been rare. Criminalising homosexuality makes them vulnerable to blackmail, they say.

Defenders of the supreme court decision said the objections of the judges to the repeal of section 377 were "constitutional and legal, not moral".

However, critics said that the wording of the judgment – which refers to the "so-called rights of LGBT persons", describes same-sex relations as "against the order of nature" and says that "lesbians, gays, bisexuals or transgenders constitute only a miniscule fraction of the country's population" – reveals deep prejudice.

Gay activists say there is increasing support for their cause. Only about a dozen people attended India's first gay pride march, in the eastern city of Kolkata in 1999.

Now thousands gather there each year and similar events are held in Delhi, Mumbai, Bengaluru and other cities. Gay film festivals and university campus groups have also sprung up. "This is not the same community as 10 years ago. This is a real call to arms," said Bhan.

Vikram Seth, the Indian prize-winning novelist, said he was hopeful. "Today is a great day for prejudice and inhumanity and a bad day for law and love. But law develops and love is resilient and prejudice will be beaten back," he told the NDTV news channel.

"I wasn't a criminal yesterday but I'm certainly a criminal today … But I do not propose to take the permission of their lordships when deciding who to love and who to make love with."