Twitter said Wednesday it had blocked some accounts in India over comments on mass farmers' protests, but the social media giant refused to shut down others despite a government threat of criminal action.

Indian officials last week demanded Twitter block hundreds of users that tweeted about demonstrations against proposed new agriculture laws, saying they were a "grave threat to public order".

Twitter initially complied by blocking a number of accounts -- including those of a prominent news magazine and farmer groups -- but unblocked them hours later, prompting threats of "penal action" from the government.

Farmers have camped on roads leading into the capital New Delhi since late November as they call for the new laws to be repealed, in one of the biggest challenges to Prime Minister Narendra Modi's government since it came to power in 2014.

International celebrities including pop superstar Rihanna and climate activist Greta Thunberg have even weighed in, drawing the ire of the foreign ministry, which called their online comments "sensationalist".

In a blog post, Twitter said it did "not believe that the actions we have been directed to take are consistent with Indian law".

"In keeping with our principles of defending protected speech and freedom of expression, we have not taken any action on accounts that consist of news media entities, journalists, activists, and politicians," the San Francisco-headquartered company said.

"To do so, we believe, would violate their fundamental right to free expression under Indian law."

The firm added that several accounts had already been "permanently suspended", while others had been blocked but only "within India".

The Ministry of Electronics and Information Technology said Twitter had "unwillingly, grudgingly and with great delay complied with the substantial parts of the order".

The ministry's secretary, Ajay Prakash Sawhney, who met virtually with Twitter executives Wednesday, said the platform reacted differently to the farmers' assault of a historic fort in Delhi in late January and the storming of the US Capitol -- by siding with "those who... provoke disturbance to public order" in India.

Twitter said on Wednesday it had suspended several accounts in connection with mass protests in India
Twitter said on Wednesday it had suspended several accounts in connection with mass protests in India AFP / Olivier DOULIERY

The secretary also stressed that "freedom of expression is not absolute" and is subject to public order interests under India's constitution.

Twitter's response comes as a tussle intensifies between India's authorities and social media services in the world's biggest democracy.

Members of India's ruling Bharatiya Janata Party (BJP) and its supporters regularly brand their critics traitors, propagandists and "anti-nationals".

Senior BJP politicians, including the party's national general secretary B.L. Santhosh, tweeted Wednesday that the platform "can't have your own rules" and had to follow Indian law.

Local media reported that New Delhi has accused Twitter of bias, saying its chief executive, Jack Dorsey, had liked tweets by celebrities supporting the farmer protests.

Digital rights activist Nikhil Pahwa said New Delhi has been challenging social media companies on content it feels is "not in its interest or in the national interest" for many years.

He said the government frequently keeps its orders to block content, made under a section of the IT Act, under a "cloak of secrecy" and called for more transparency.

"I'm very glad if Twitter is challenging the government if it believes that these orders are not lawful orders, because many times, companies tend not to challenge... because the government is so powerful," he told AFP.

Some local personalities including Commerce and Industry Minister Piyush Goyal have opened accounts on rival Indian social network platform Koo.