The party of Prime Minister Atal Bihari Vajpayee conceded the vote, leaving Sonia Gandhi, the Italian-born widow of the former Prime Minister Rajiv Gandhi, to take the helm of the world's largest democracy.
Vajpayee resigned Thursday night but was to stay on until the new government is formed, the president's secretary said. He was to address the nation later on television.
It was one of the most dramatic political upsets since Indian independence almost 60 years ago.
"We have not got the mandate of the people," said Venkaiah Naidu, president of Vajpayee's Bharatiya Janata Party. He said the decision to concede the race was made at a 90-minute meeting of the party and its coalition partners.
The opposition Congress Party and its allies had already claimed victory, and some promised that Gandhi, the party leader, would be the next prime minister. There was still no official decision, however, and she must form a coalition with leftist parties that could object to her taking the leadership role — in part because of her foreign origins.
After more than 11 hours of vote-counting for 539 of Parliament's 543 elected seats, official results showed Congress and its allies were leading Vajpayee's 11-member National Democratic Alliance 178 seats to 146 seats.
Sonia Gandhi won a seat in the northern town of Rae Bareli. Her son, 34-year-old Rahul, won a seat in Amethi, her previous constituency.
Gandhi now faces the same challenges as she did in 1999, when she failed to take over the government due to disagreement over whether she should become prime minister. Among her potential allies on the left are senior politicians with much more experience; without their support she won't have a majority in Parliament.
George Fernandes, defense minister under Vajpayee, said the new Parliament could meet as early as Monday.
It was an embarrassing defeat for Vajpayee's Hindu nationalist-led government, which had called elections six months early because it felt confident of winning an even bigger majority in Parliament, based on the roaring economy and prospects of peace with Pakistan.
Before the five-phased elections, which began April 20, Vajpayee and his alliance had been expected to win enough seats to eventually form a government and rule the country for another five years.
But Congress focused its campaign on the country's 300 million people who still live on less than a dollar a day. It hammered away at the lack of even basic infrastructure, electricity and potable water for millions of rural poor.
A leader in Vajpayee's coalition said the results were "totally against our expectations."
Pakistan expressed confidence Thursday that the peace process would continue despite the NDA defeat. Information Minister Sheikh Rashid Ahmed told The Associated Press that the process involved the two governments, not "individual personalities."
Meanwhile, in Gujarat state, the heartland of support for the Hindu-dominated BJP, voters appeared to reject religion-based politics, slashing the party's representation in Parliament. Gujarat was the scene of violence between Hindus and Muslims that killed 1,000 people in 2002.
Gandhi has pushed for a secular India in contrast to the BJP's Hindu nationalist message. Her two children, Rahul and Priyanka, are up-and-coming politicians and state-run television reported that Rahul won his race to enter parliament for the first time.
The Gandhi dynasty dominated Indian politics since independence from British colonial rule in 1947. Jawaharlal Nehru, India's first prime minister, headed the country from independence until his 1964 death. He was followed by his daughter, Indira Gandhi, who was killed by her own bodyguards in 1984.
Rajiv, her son and Sonia's husband, took power and ruled until 1989. Two years later, he too was assassinated.
The family is not related to Mohandas Gandhi, India's independence leader.
During the campaign, Mahajan had called Gandhi's Indian-born children foreigners and had stoked the debate — dubbed the "Sonia factor" — over whether a foreign-born citizen should rule India.
Outside Sonia Gandhi's residence, supporters celebrated, beat drums, and set off firecrackers.
"They said she is a foreigner, but people have given them a reply," said Rati Lal Kala, 35, carrying a huge Congress flag and wearing a scarf in Congress colors. "The BJP has only played with the people's emotions. This should be a lesson for them."
Leftist parties, which have promised to support a Congress-led government, also appeared to be doing well and they could give the opposition the edge it would need to take power.
New Delhi Television — reporting trends from 535 constituencies, said Congress and its allies would likely win 218 seats, compared to 195 for the Bharatiya Janata Party-led governing coalition, and 122 for others.