Only one month ago, Narendra Modi, India’s once unstoppable prime minister, seemed surprisingly vulnerable going into his re-election campaign.
Economic growth had been slowing, thousands of farmers were marching on the capital (some even dumped gallons of nearly worthless milk in the streets), and unemployment had hit its worst level in 45 years — an unpleasant fact that Mr. Modi’s government tried to hide.
In a recent batch of critical state elections, his party got trounced. And with the country’s weekslong election process set to begin on April 11, the rejuvenated opposition was landing punch after punch with corruption allegations.
But one bombing in Kashmir, and weeks of military brinkmanship with Pakistan afterward, appears to have interrupted Mr. Modi’s slump.
A young suicide bomber blew up a military bus in Kashmir on Feb. 14, killing more than 40 troops. The group Jaish-e-Muhammad, which operates from Pakistan and is listed as a terrorist organization by the United States, claimed responsibility.
Mr. Modi ordered airstrikes on Pakistan, which he blamed for the attack, and Pakistan struck back. Never before, experts said, had two nuclear-armed nations bombed each other.
From the outside, Mr. Modi was widely criticized as being willing to risk war for even the chance at a political boost. And when an Indian pilot was captured in Pakistani territory — and was then quickly returned in a good-optics moment for Pakistan — some international analysts thought Mr. Modi’s military adventurism had backfired.
But that’s not how it has played out within India.
Political analysts say that Indians are rallying behind Mr. Modi again, and that he seems to be making crucial gains among independent and undecided voters.
The fact that India’s airstrikes probably missed their targets, and that a fighter jet was shot down by Pakistan, doesn’t seem to matter to most Indians. Their country was hit, and Mr. Modi hit back.
“Even if they go below the seven seas, I will find them,” Mr. Modi said in a speech this month, referring to terrorists. “To settle the score is my habit!”
Some of his supporters in India see Mr. Modi’s aggressive stance not as pandering for votes, but as a return to his old passion and focus.
“Whatever our criticisms about him regarding the economy and jobs, at the end of the day he has done an incredible job of delivering justice for the martyrs,” said Prapti Bhattacharya, a law student and first-time voter.
“Before this, I would have voted for Congress,” the leading opposition party, she said. “Now I’m voting for Modi.”
The Pakistan crisis “has provided him with a golden narrative,” said Milan Vaishnav, the director of the South Asia Program at the Carnegie Endowment for International Peace. “The thing about a national security crisis is that it plays up decisiveness, leadership and nationalism. These are three characteristics he often touts.”
Still, a lot can happen over the next few weeks.
India has a parliamentary system, and for Mr. Modi to return to power, his Bharatiya Janata Party must win a majority of the 543 elected seats in the lower house of Parliament or form a coalition with regional parties. The same goes for the Indian National Congress party, which ruled India for about 50 of the country’s 71 years of independence.
Congress’s leader, Rahul Gandhi, is determined to swing the election discussion back to domestic issues.
Mr. Modi’s biggest vulnerability is the economy. Even though the country’s economy grew 6.6 percent in the most recent quarter, still faster than most developed countries, it was India’s slowest rate in five years.
With a population of 1.3 billion and improving education, India produces nearly half a million new job seekers each month. This would be an overwhelming burden for any leader, and Mr. Modi raised expectations even higher by promising to create 10 million jobs, a wildly ambitious goal that, by most accounts, he has failed to achieve.
“We haven’t created jobs — we have actually lost jobs,” said Mahesh Vyas, the chief executive of the Center for Monitoring Indian Economy.
By his count, India now has about 400 million jobs, down slightly over the last three years.
Another problem for Mr. Modi is dissatisfaction among Dalits. India’s centuries-old caste hierarchy — with Dalits at the bottom, Brahmins at the top and many groups layered in between — still dominates life in many areas, especially rural ones.
Lower castes still face horrendous abuse, and Dalits — who represent close to 100 million votes — have long distrusted Mr. Modi and his party, which is rooted in a Hindu nationalist worldview that favors upper castes and emphasizes India’s Hinduness.
But in the last election, in 2014, Mr. Modi played up his humble origins — the son of a tea seller from a relatively low caste. Analysts said that 24 percent of Dalits voted for his party, double the percentage from the previous election.
This time around might still be very different, even with a bump from the showdown with Pakistan.
Mr. Modi himself has not made disparaging remarks about minorities, but in the wake of this kind of violence, he is often silent. Many officials in his party, including ministers, have taken what are widely considered extremist positions when it comes to protecting cows, a sacred animal in Hinduism, or siding with vigilantes who target Muslim or low-caste butchers.
While many conservative Hindus see Mr. Modi as an unswerving defender of some of their most deeply felt values, many Dalits and Muslims are frightened of their own government. Despite Mr. Modi’s pledges to unify India — he often repeats his slogan, “Sabka Saath, Sabka Vikas,” or “All together, development for all” — many observers say India has become more polarized along caste and religious lines during his time in power.
Chandra Bhan Prasad, a well-known political commentator and a Dalit, said few Dalits would change their mind on Mr. Modi because of the action on Pakistan.
“He’s totally lost the Dalit vote,” Mr. Prasad said. “Dalits will still vote for any party that can defeat the B.J.P.”
If true, that could mean the loss of millions of votes.
Farmers were another concern for Mr. Modi, but here, the action on Pakistan could make a difference.
At 260 million strong, farmers are the biggest single voting bloc in India, and many had been furious with Mr. Modi.
He had promised to ensure that farmers received prices high enough to make a profit, but export controls and overproduction have cut deeply into prices for crops like onions and potatoes.
Tens of thousands of farmers have descended on cities, pouring milk into the streets and dumping vegetables onto sidewalks. One farmer sent the paltry $15 he had earned selling 1,600 pounds of onions to Mr. Modi.
But after the crisis with Pakistan, the conversation on many farms has changed, said Vijay Jawandhia, a farmer and leader of a farmers’ union from Maharashtra State.
“I hear farmers saying he is more decisive,” he said.
According to Gilles Verniers, an assistant professor of political science at Ashoka University, near New Delhi, 40 percent of India’s 900 million voters typically remain undecided until right before the election. Unlike with politics in the United States, where people tend to pick a party and stick with it, many voters in India tack back and forth between the major parties depending on the candidates and the issues of the day.
Mr. Verniers said the crisis with Pakistan was certain to “tame the decline” Mr. Modi had been facing.
Before the attack in Kashmir, a disputed territory that both India and Pakistan claim, Mr. Gandhi, the leader of the Congress party and the scion of a storied political dynasty, had gained a new spring in his step. He was speaking out forcefully about a murky jet fighter deal that Mr. Modi’s government made with France, and he enlisted his popular younger sister, Priyanka, to join the campaign, delivering it a jolt of energy.
Both Congress and the B.J.P. have struck alliances with regional parties in the hopes of forming a governing coalition. The biggest leftist parties, including communists and those dominated by lower castes, are likely to back Congress, while some of the largest parties in Punjab and Maharashtra, two populous states, are firmly on Mr. Modi’s side.
As of now, Mr. Modi is the “odds-on favorite,” said Ashutosh Varshney, the director of the Center for Contemporary South Asia at Brown University.
“But I think the narrative can change,” he said. “There is still a great deal of anger at Mr. Modi.”