Earlier this month police arrested a teenager for a Facebook post which they said ‘carried derogatory language against a community’.
Photograph: Indranil Mukherjee/AFP/Getty Images

India’s supreme court has struck down a controversial law that made posting “offensive” comments on social media a crime punishable by jail.

The decision on Tuesday came after a two-year campaign by free speech activists, led by a law student.

In a decision that surprised many, judges said an amendment to India’s Information Technology Act known as section 66A was unconstitutional and a restriction on freedom of speech.

“The public’s right to know is directly affected by section 66A,” said Justice R F Nariman, reading out the judgment.

The law, which received presidential assent in 2009, makes posting information of “grossly offensive or menacing character” punishable by up to three years in jail. Campaigners claimed that it was repeatedly misused by police.

Other cases include a university professor detained for posting a cartoon about the chief minister of the state of West Bengal.

In 2012 two young women were arrested under the act over a Facebook post criticising the shutdown of Mumbai, India’s commercial capital, after the death of a local hardline politician. One was arrested simply for “liking” the post, relatives said.

The charges were later quashed by a Mumbai court but sparked outrage and fierce debate about online censorship in India.

Karuna Nundy, a well-known lawyer who represented campaigners in the supreme court hearings, said section 66A had been “a blot on the constitution”.

Nundy said: “People who have taken on the biggest bullies can now speak without fear. The sense of freedom is wonderful. In these times of crackdowns on free speech around the world, and in India too, I am glad that our constitution still redeems us.”

The judgment runs to more than 200 pages, and is expected to deal with a range of issues related to online censorship.

Politicians from all major parties in India welcomed the decision, though a spokesman for the rightwing Shiv Sena group said section 66A should remain to prevent “misuse” of the internet.

A spokesman for the ruling Bharatiya Janata party spoke of a “landmark day for freedom of speech and expression”.

Ravi Shankar Prasad, the communications and law minister, told reporters that the government had earlier believed that firm guidelines should have been put in place to ensure the law “was in concordance with freedom of expression” as guaranteed by the constitution.

In court, government lawyers had agreed that the law had been misused, but argued that it was necessary to have some means to regulate offensive material on the internet.

Manish Tewari, a politician from the Congress party, said the law “had become an instrument of oppression”.

Tewari was minister for information and broadcasting in the previous government, led by the centre-left Congress party, which introduced the law.

Other Congress officials said the law had been “poorly drafted”.

India is described as “partly free” in terms of expression of opinion on the internet by US campaign group Freedom House. Neighbouring Pakistan and China were designated “not free”.

“In general, self-censorship is not widespread [in India],” the group said in their 2014 report, though “criminal penalties on online speech in India have had a ‘chilling effect’ on online speech”.

Shreya Singhal, the young law student who petitioned the court on Section 66A, described the decision as “a victory for the country”.

Questions of surveillance and censorship continue to fuel fierce argument in India. There are around 200 million internet users in the developing south Asian power, the third highest total in the world, although telecommunications infrastructure remains inadequate.

Last month a BBC documentary on the gang-rape and murder of a student in Delhi in 2012 was banned from public screenings and broadcast in India.

Facebook has reported that 5,832 pieces of content were restricted between July and December 2014 following requests from India, “primarily by law enforcement agencies and the India computer emergency response team including anti-religious content and hate speech that could cause unrest and disharmony”.

The Indian supreme court has a long history of intervening in controversial cases, and has often, though not exclusively, supported progressive arguments on human rights issues.

One problem, campaigners say, is that laws dating back to the 19th century dealing with “sedition” are being applied to online comment.

Nundy, the lawyer, said much more needed to be done.

“There has been no comprehensive overhaul of laws put in place by the [British] colonial government that had no interest in free speech,” she said.