Demonstrators in New Delhi denounce an attack last month by Pakistan on an Indian military convoy in Indian-controlled Kashmir. (Sajjad Hussain/AFP/Getty Images)

The first time Sandeep Wathar received a message on Facebook from a total stranger calling him a traitor, he was amused. When dozens more followed, he knew something was wrong.

After India and Pakistan nearly went to war last week, Wathar, a 29-year-old professor of civil engineering in the southern Indian state of Karnataka, vented his frustration on social media. In a Facebook post, he used expletives to refer to India’s ruling party and said it had endangered millions of lives.

Two days later, students and members of a right-wing Hindu group gathered outside his office demanding he apologize for his “anti-national” comments. As a police officer watched, the crowd ordered Wathar to kneel and beg for forgiveness. So he did.

“It’s very obvious now that it can happen to anybody,” Wathar said.

A wave of angry nationalism has swept India in recent weeks, triggered by a Feb. 14 suicide bombing that killed 40 Indian security personnel in the disputed region of Kashmir and then by a military confrontation with Pakistan, the country’s oldest foe.

Television anchors have called for revenge and portrayed any questioning of the Indian government or armed forces as equivalent to helping Pakistan (one particularly strident channel recently pushed the hashtag #ExposePakLovers).

That message has been amplified by the country’s leadership: Prime Minister Narendra Modi, who is seeking reelection this spring, has cast opposition parties as disloyal for asking about the efficacy of India’s Feb. 26 retaliatory airstrike on Pakistan. Modi leads a Hindu nationalist political party, and since his election in 2014, hard-line Hindu groups have become more assertive, sometimes resorting to violence.

In recent weeks, some of those publicly critical of the government or India’s military have been suspended from their jobs.

Kashmiri Muslims living elsewhere in India have faced the brunt of the backlash, with students being hounded out of their universities and vendors being physically attacked. Late last month, the country’s Supreme Court ordered the government to step up protection of Kashmiris and other minority groups.

The recent climate marks a new turn for India, said Harish Khare, a leading columnist and former editor of the English-language Tribune newspaper. He blamed the government, saying it had “stampeded the country into a volatile, edgy, anxious nationalism.”

The dramatic events of late have raked up old conflicts — such as the anti-India insurgency in Kashmir and the rivalry between India and Pakistan — in a new social media age. India is the largest market in the world for Facebook and WhatsApp and the fastest-growing market for Twitter

Online mobs have been swift to attack even the most unexpected targets. Mita Santra’s husband was one of the paramilitary officers killed in the Feb. 14 suicide bombing in Kashmir. But after the 38-year-old teacher publicly stated in the wake of her husband’s death that war should be the last option, she was roundly criticized on social media. Other users later rallied online to support her.

Santra, who lives in the state of West Bengal, remains defiant. “This is a democracy,” she said. “I have the right to say what I want.”

For others, the consequences of speaking their mind have been more serious. Days after the Feb. 14 attack, Madhumita Ray, a sociology professor in the state of Odisha, appeared on a local news show where she had a heated exchange with a retired army colonel.

Ray said war with Pakistan was not the solution and evoked Mahatma Gandhi’s philosophy of nonviolence. She also mentioned the Indian army’s excesses in places such as Kashmir and India’s northeast. Ray said the retired colonel shot back that she was “anti-national” and people like her should be “slapped.”

Manoranjan Mishra, the television anchor who moderated the segment, said he received angry calls and messages after the show aired, including one saying Ray should be killed. The channel decided not to upload a video of the segment to its website.

“When sentiment is high, we shouldn’t hurt the emotions of our viewers,” said Mishra. The only other time he recalled a similar level of public anger was when deadly communal riots convulsed the state of Odisha in 2008. But back then, “social media was not in the picture,” he said.

A few days later, Ray says she was asked to resign from her post by administrators at the Kalinga Institute of Industrial Technology in Bhubaneswar. A college official said Ray had resigned, citing personal reasons. Ray said she had expected a reaction to her comments but was shocked to find the cost was her job.

In another sign of the times, a government minister publicly questioned the patriotism of a prominent journalist who had asked him about proving the impact of India’s Feb. 26 airstrike on an alleged terrorist camp in Pakistan. Such questions “belittle our armed forces” and are a “matter of shame,” said Piyush Goyal, India’s minister for coal and railways.

Wathar, the professor who was forced to kneel and apologize, is unsure of his future. His college has instituted a committee to examine the episode and has asked him to explain his online comments. Meanwhile, Sachin Bagewadi, 21, a computer science student from a right-wing Hindu group who took part in the incident, said Wathar’s “anti-national” post had received a fitting response.

“I didn’t think anybody would get offended by an ordinary person like me,” said Wathar. “I was only raising a question to the government.”