Sonia Gandhi, former Congress president, called Mr Gowda this afternoon and they agreed on the terms of their potential partnership. Before the election, both parties had refused to enter an alliance. The Congress' Chief Minister, Siddaramaiah, split from the JDS over a decade ago and the acrimony between him and Mr Gowda remains unmitigated.

However, as a series of opinion and exit polls forecast a fractured result, the Congress made it clear that it would be open to sacrificing Mr Siddaramaiah if needed to team with the JDS. Mr Siddaramaih himself appeared to have accepted his being turfed out, stating that this was his last election and that he would accept his party's decision to replace him with a Dalit as head of the state if needed.

Senior Congress leader Ghulam Nabi Azad said, "we have had a telephonic talk with Deve Gowda and Mr Kumaraswamy and they have accepted it. Whoever JDS will decide, will head the government and then we will go to governor and give this in writing."

As the BJP surged ahead in the first few hours of counting, celebrations erupted at the BJP's offices in Bengaluru with supporters shouting victory slogans and waving the party's flag and cut-outs of PM Modi. The BJP has won 107 seats, which is five short of the majority.

Karnataka is another disappointment for the Congress and Rahul Gandhi, who took over as party president in December. Congress leaders said the party had failed to capitalise on the dissatisfaction over farmers unrest, lack of jobs and rising fuel prices. If the Congress loses Karnataka, it will be difficult for Rahul Gandhi to claim leadership in any opposition alliance against the BJP in 2019. The party now holds only three states - Punjab, Puducherry and Mizoram.

Had the Congress formed an alliance with the Janata Dal Secular before the Karnataka election, the poll outcome would have been "very different", said West Bengal Chief Minister Mamata Banerjee, who has been at the forefront of attempts to evolve a non-Congress, non-BJP front ahead of the national election.

The BJP made big gains in the Scheduled Caste and Scheduled Tribes (SC/ST) belt, which was in part because of the "Sriramulu" effect. The BJP bet on B Sriramulu, a powerful SC/ST leader and a close aide of the powerful Reddy brothers of Ballari, giving him two seats to contest. The BJP's score also indicates the Lingayats have stayed with the party despite Chief Minister Siddaramaiah of the Congress announcing minority status to them as members of a separate religion.

The BJP's own analysis was that Rahul Gandhi declaring himself a prime ministerial candidate was a big reason for the party's defeat. "The Congress played divisive politics and Siddaramaiah is not a big leader," said Union Minister Ravi Shankar Prasad.

Karnataka has maintained its long-standing habit of not supporting the incumbent; no party has been re-elected in the state for 30 years. Karnataka Congress' DK Shivakumar said though "Rahul Gandhi tried his best", the local leadership including Siddaramaiah had failed the party.