Narendra Modi has secured the backing of his political allies in order to form a government and is expected to be sworn in over the weekend, after a dramatic election in which his party failed to secure an outright majority.

At a meeting in Delhi after Tuesday’s shock results, parties in the National Democratic Alliance, which is led by Modi’s Bharatiya Janata party (BJP), pledged their support to Modi and backed his return as prime minister for a historic third term. “We, the leaders of the NDA, unanimously elect Narendra Modi as our leader,” the party leaders said in a resolution.

The BJP lost more than 60 seats in Tuesday’s polls, bringing its total down to 240 – not enough for a parliamentary majority on its own. It was the party’s worst electoral performance since it came to power in 2014 and was seen as a big blow to Modi.

But by Wednesday afternoon the BJP-led alliance had announced an agreement to form a coalition government after a meeting at the prime minister’s residence, which would give them a total of 293 parliamentary seats.

The BJP’s campaign had been largely centred on the strongman prime minister and relied heavily on the popularity and cult of personality of Modi, with a manifesto that was simple titled “Modi’s guarantee”.

However, the party suffered unexpectedly heavy losses in Hindi heartland states which had previously been considered BJP bastions, including Uttar Pradesh, home to 240 million people, after swathes of lower-caste voters turned against Modi and the Hindu nationalist politics of his party.

Exit polls over the weekend had failed to capture the groundswell of discontent against Modi among poorer, rural voters, leading to wildly over-optimistic predictions of success for the BJP. Pradeep Gupta, the head of the Axis My India poll agency, which had predicted a two-thirds-majority landslide for Modi, said this was “my mistake” and admitted it had mostly spoken to more privileged male voters to reach its conclusions.

Several of the parties that Modi will rely on to form a coalition government had previously been aligned with opposition parties such as Congress and do not share the BJP’s rightwing, Hindu-nationalist politics, identifying as secular.

Analysts said Modi could be forced into a more conciliatory style of politics than over the past 10 years and may have to tone down his religious nationalist agenda, which aims to make India a Hindu state as opposed to a secular one.

Map: general election results across India

Earlier in the day, Modi had tendered his resignation as prime minister before the formation of the new government. The ceremony to swear him in for a third time is likely to take place on Saturday.

skip past newsletter promotion

In his final cabinet meeting, Modi addressed the losses faced by his party in the election. “We have done good work for the last 10 years and we will continue doing so,” Modi told his cabinet ministers. “Winning and losing are part of politics. The numbers game will go on.”

The opposition alliance of more than 20 parties performed far better than expected, winning 232 seats. Dozens of leaders from the coalition, which goes by the acronym INDIA, met on Wednesday to discuss their next steps.

Mallikarjun Kharge, the president of the Congress party, the largest opposition party in the INDIA bloc, said the results were a “befitting reply to the BJP” and that the alliance would “continue to fight against BJP’s fascist rule”.

“The mandate is decisively against Mr Modi, against him and the substance and style of his politics,” said Kharge in his opening remarks at the meeting. “It is a huge political loss for him personally apart from being a clear moral defeat as well. However, he is determined to subvert the will of the people.”