In the end, India’s ruling Bharatiya Janata Party (BJP), registered yet another victory in Prime Minister Narendra Modi’s home state of Gujarat. But it was the kind of victory where the winners were more relieved than overjoyed. And the losers were not despondent but encouraged.

Gujarat is Modi’s bastion. He made his reputation there as a charismatic chief minister with administrative skills and remains its favourite son, the most popular leader to emerge from the region in the past five decades.

But it is also where he earned international notoriety in 2002 over accusations that his administration did not do enough to protect Muslims during bloody sectarian riots. Though many countries (including the United States) refused Modi a visa after those riots, his popularity within his own party soared, and in 2014 he led the BJP to the biggest national electoral victory since 1984.

So, when elections for the state assembly in Gujarat were announced, the polls were seen as a walkover. Not only were the people of Gujarat excited that one of their own had become prime minister, but Modi’s BJP had just won a landslide victory in the major state of Uttar Pradesh. So high were the BJP’s confidence levels that its party president Amit Shah (a key Modi confidant from his Gujarat days) declared that the BJP would win 150 of Gujarat’s 182 seats.

At the time, the boast seemed credible. The BJP had won 60 per cent of Gujarat’s votes in the 2014 parliamentary election. Its principal opposition, the Indian National Congress, had no organisational machinery in Gujarat and no state-level leader. Moreover, a few months before the polls, 14 Congress legislators revolted and supported the BJP.

But when the results came in today, it was clear that Shah’s confidence was misplaced. The BJP still won, as all opinion polls had said it would, but it was not the sweeping victory Shah had predicted and considerably below levels predicted by some exit polls.

Current figures suggest that the BJP will win under 100 seats, a drop from the 115 it won in the last election. The Congress, which went into the election as a no-hoper, managed a respectable performance in defeat, winning 81 seats, a gain on the 61 it won last time.

Modi is facing a perfect storm in Gujarat. Can he weather it?

As the results came in, the BJP argued with some justification that a win was a win. And indeed there are few instances in recent Indian electoral history where a party has won a fifth consecutive term. To be able to shrug off the anti-incumbency factor after more than two decades is a not inconsiderable achievement.

But equally, it was clear that the Modi juggernaut, seemingly unstoppable since the Uttar Pradesh landslide victory, had slowed. And though the final results were a relief, the campaign had been full of nervous moments that the BJP never anticipated.

Initially, Modi had said that the election would be about vikas or development. But the Congress made inroads mocking his claims, suggesting that development had ground to a halt. It also focused on the downsides of demonetisation, one of Modi’s pet schemes, such as its massive inconvenience and the subsequent implementation of a goods and services tax, a new federal tax.

The BJP made some attempts to counter these criticisms, announcing many reforms in the structure of the new tax, but it was unable to effectively counter the discontentment among a caste group called the Patidars, or Patels, who had long been BJP supporters. When the Congress linking up with the young leaders of this group, the BJP recognised that it had a battle on its hands.

Withdrawal symptoms: cash is still king in India, Modi not so much

The biggest surprise for the BJP however, was the performance of Rahul Gandhi. Since 2014, Gandhi, son of the then Congress President Sonia Gandhi and heir apparent (he eventually became Congress president just as the Gujarat election ended), has been caricatured by the BJP as an entitled buffoon with no political skills. But during the Gujarat campaign, he got his act together, became an effective campaigner and attracted huge crowds to his political events.

Voting in Gujarat was divided in two phases, separated by a few days. Just as the first phase was drawing near, the BJP unleashed its most powerful campaigner: the prime minister.

When Modi barnstormed the state, he abandoned the themes of development and launched a more communally charged attack focusing on Hindu-Muslim conflicts . He raked up the Babri Masjid issue (a dispute over a medieval mosque that the BJP first raised in the 1980s) and then went so far as to suggest that the Congress was taking the help of Pakistan to defeat him. He alleged that the Pakistan high commissioner and a former Pakistani foreign minister had met with former Indian prime minister Manmohan Singh (a Congressman) to plot the BJP’s defeat in Gujarat. When the Congress retorted that this was a dinner attended by several former senior diplomats and a former army chief, Modi refused to temper his rhetoric.

It is hard to say whether Modi actually believed any of his allegations. But what is indisputable is that the BJP campaign had switched to sectarian messaging.

Posters went up suggesting that Ahmed Patel, a Muslim, would be chief minister if the Congress won. Gandhi, who had visited two dozen temples in an effort to prove that the Congress was not anti-Hindu, was accused of not really being a Hindu.

When the results came in, the BJP breathed a sigh of relief. It had successfully fought off the Congress challenge. But there were still causes for concern. The party did much better in the second phase of polling than it did in the first, suggesting that Modi and his imaginative rhetoric had contributed substantially to the victory. He might even have swung the crucial votes needed to win.

India: no country for Muslims

More significant was that the Congress’ gains came from the more rural Saurashtra region, a separate state until it merged with Gujarat in 1960. Agrarian distress is a major issue in India; here at last was proof that it could hurt the BJP electorally. As worrying for the BJP was that in Patidar seats, the Congress (aligned with young Patidar leaders) did much better. And most worrying of all was that, even though he lost the election, Gandhi proved that he was not the ineffectual joker the BJP has always treated him as.

But the Congress also came to terms with its own limitations. The party’s failure to make any dent in Gujarat’s cities – the backbone of the BJP’s victory – is significant. It suggests that while the Congress can successfully appeal to the poor, it has not been able to reach out to the urban middle class, which remains enthralled by Modi’s charisma.

There are worrying signals for India, too. Modi’s rhetoric in the last stages of the campaign – suggesting that his predecessor as prime minister consorted with Pakistani agents – marks a considerable drop in the level of Indian political discourse. But the BJP appears to believe that it worked. So future campaigns may be even dirtier and characterised by more divisive sectarian rhetoric.

Ram redux: will India return to the days of temple strife?

This result should give the Congress some encouragement. The real battles will be fought next year in the states of Rajasthan and Madhya Pradesh where the BJP may be more vulnerable. If Gandhi can defeat the BJP in those states, the Congress has a chance of stopping Modi at the next parliamentary election due in 2019.

The Modi juggernaut may roll on. But there are bumps in the road ahead.