The party of Indian prime minister Narendra Modi has suffered heavy election defeats in two states, with another on a knife edge, in a bruising day of results that exposed the party’s vulnerability less than six months before the country goes to the polls.

The main opposition Congress party decisively won state elections in Rajasthan and Chhattisgarh and has a narrow lead in Madhya Pradesh, where votes were still being counted on Tuesday evening.

The governing Bharatiya Janata party’s (BJP) vote collapsed by 17 percentage points in Rajasthan state and by at least 12 points in Chhattisgarh and Madhya Pradesh, all part of the Hindi heartland where Indian governments are traditionally made or broken.

Those losses, as well as the revival of a Congress party frequently written off in the past five years, had analysts revising their predictions for next year’s national polls, which Modi had been expected to win in a cakewalk.

Indian prime minister Narendra Modi stands with BJP leaders at the winter session of parliament in New Delhi. Photograph: Money Sharma/AFP/Getty Images

“I think election 2019 is going to be a fight for Modi,” said Nilanjan Mukhopadhyay, a political commentator and biographer of the prime minister. “These losses came not just in the Hindi heartland, but in the heart of the Hindi heartland.”

He said the results — from elections held in the past week but formally counted on Tuesday — were a reflection of the poor performances of the incumbent state governments, but also a backlash against Modi’s administration for “failing to deliver on its promises”.

Television footage showed jubilant Congress workers bursting firecrackers and dancing at regional party offices.

The government has contended with large protests in recent weeks by farmers in distress due to natural disasters and falling prices. Nearly 55% of India’s 1.25 billion population is directly or indirectly dependent on agriculture, and farmers form an important voting bloc for parties.

The BJP has also faced criticism from Hindu nationalist groups unhappy at the delay in building a temple to the deity Ram in his fabled birthplace Ayodhya. Unemployment also remains a problem despite high economic growth.

Television footage showed jubilant Congress workers bursting firecrackers and dancing at regional party offices. Photograph: Adnan Abidi/Reuters

Yet Modi’s personal popularity remains significant. In Mandsaur, a Madhya Pradesh rural town surrounded by yellow rapeseed fields, six farmers were shot and killed during one demonstration last year. The BJP lost surrounding districts on Tuesday but surprised analysts by holding Mandsaur, where Modi held a raucous campaign event in November.

“Paradoxically, the popularity of Modi is not correspondingly falling with his government’s,” said Mukhopadhyay. “The government is getting flak but Modi is not.”

Tuesday’s results were a vindication for Rahul Gandhi, the president of Congress, a scion of India’s establishment party but a young leader who has struggled to convince that he has the mettle to defeat Modi, India’s most formidable politician in a generation.

Congress tweeted on Tuesday evening: “Democracy has won! Thank you India, you have chosen love over hate, peace over violence & truth over lies. This victory is yours.”

Regional parties triumphed in separate polls in the smaller states of Telangana and Mizoram that were also released on Tuesday.