Mr. Modi, who had eagerly cast the Bihar elections as a referendum on his first 17 months as India’s leader, acknowledged defeat shortly after noon.
Recriminations were swift within his Bharatiya Janata Party, or B.J.P. Some party leaders questioned whether Mr. Modi had erred in the closing weeks of the Bihar campaign by elevating hard-right appeals to Hindu nationalism over his more unifying message of “vikas,” or development, for all Indians.
Those appeals — in which Mr. Modi depicted his opponents as favoring Muslims and insulting cows, a revered Hindu holy symbol — fell flat in Bihar, a desperately poor state in eastern India where millions of people eke out a living as subsistence farmers without electricity, plumbing or even two meals a day.
While pollsters had predicted a close election, the actual results were anything but: The B.J.P. and its allies won less than half as many seats in the 243-member state assembly as the “grand alliance” of parties that joined forces to oppose Mr. Modi.
One prominent political analyst, Shekhar Gupta, summed up the lesson of the election this way: “Mr. Modi is beatable.”
The defeat also means that Mr. Modi will enter the winter session of Parliament without the political momentum he craved to force through major overhauls of taxation, labor rules and land use that he sees as critical to accelerating India’s growth and attracting more foreign investors. The loss also deprives the B.J.P. of a vital location from which to spread its political dominance into northeast India, including the large state of West Bengal.
The battle for Bihar, fought through five rounds of voting over the past five weeks, played out against a raging national debate over whether Mr. Modi’s India is becoming increasingly intolerant of secularists, Muslims and political dissent in general. According to the police, four Muslims were attacked and killed by mobs of Hindus in the past six weeks because they were suspected of stealing, smuggling or slaughtering cows.
Hundreds of writers, filmmakers, scientists and academics have protested what they see as rising intolerance by signing petitions or returning awards they had received from government-supported bodies.
“This is a victory of unity over divisiveness. Humility over arrogance,” said Rahul Gandhi, a leader of the Congress party and a member of the grand alliance, in a statement. Mamata Banerjee, the chief minister of West Bengal, called it a “defeat of intolerance.”
Mr. Modi said little about Sunday’s results, other than mentioning on Twitter that he had telephoned Nitish Kumar, the leader of the grand alliance and the current chief minister of Bihar, to congratulate him. (Mr. Kumar, in turn, posted on Twitter expressing his gratitude for the call.)
Mr. Kumar proved a formidable opponent, especially after he did the unthinkable and teamed up with his longtime rival in Bihari politics, Lalu Prasad Yadav, to defeat Mr. Modi. The two men, masters of manipulating caste politics, have run Bihar for the past 25 years, and they gleefully portrayed Mr. Modi as a globe-trotting elitist outsider who had consistently failed to deliver on his big promises.
In a recent interview, Mr. Kumar said Mr. Modi had “aroused the expectations of the people” when he was elected prime minister last year, but had little to show for it.
“He has done nothing,” Mr. Kumar said, previewing a message Mr. Modi’s opponents are already beginning to amplify.
Indeed, in a raucous, celebratory news conference on Sunday, Mr. Yadav wasted no time in saying that he and the rest of their alliance would try to dethrone Mr. Modi as prime minister.
“Remove Modi, save the nation,” Mr. Yadav said.