Former prime minister Nawaz Sharif appealed to all parties to join him in tackling Pakistan's mountainous problems after securing victory in historic elections that defied Taliban violence.
Partial, unofficial results from Saturday's election represented a stunning comeback for a man deposed in a 1999 military coup -- but he looked short of an outright majority, raising the prospect of another weak coalition government.
The party of former cricket star Imran Khan -- whose promises to end corruption resonated with middle-class and youth voters -- conceded defeat but vowed to form the next provincial government in the restive northwest, where Khan has vowed to end US drone strikes.
The landmark polls mark the first time an elected civilian administration completed a full term to hand power to another through the ballot box, in a country where there have been three military coups and four military rulers.
Official results were emerging only slowly early on Sunday but TV projections suggested no single party would win a simple majority of 172 seats in the national assembly.
According to the private TV network Geo, Sharif's centre-right Pakistan Muslim League-N (PML-N) was leading the race with 126 seats and Khan's Pakistan Tehreek-e-Insaf (PTI) had 34.
With just 32 seats so far, the Bhutto clan's Pakistan People's Party (PPP) -- which led the outgoing government with 125 seats in the old national assembly -- was relegated to a humiliating third place.
Flanked by his brother Shahbaz and his daughter Maryam, Sharif gave a victory speech late Saturday to hundreds of jubilant supporters at PML-N headquarters in Lahore.
"We should thank Allah that he has given PML-N another chance to serve you and Pakistan," he said, after nearly 60 percent of the 86 million electorate turned out to vote despite polling day attacks by the Taliban that left 24 dead.
Sharif, who has vowed a pro-business agenda to revive Pakistan's crippled economy, struck a conciliatory tone following Khan's high-voltage campaign.
"I appeal for all parties to come to the table and sit with me and solve the country's problems," Sharif said.
The election was fought over the tanking economy, an appalling energy crisis that causes power cuts of up to 20 hours a day, the alliance in the US-led "war on terror" and chronic corruption.
Prime minister twice before in the 1990s, Sharif's historic third term will begin only after he brokers a deal with political rivals to form a coalition.
But his supporters hailed a new day for the nuclear-armed country. Youths in Lahore danced in the streets holding stuffed tigers -- the PML-N's election symbol -- and people offered sweets to celebrate the win.
Political analysts said the result would most likely be a hung parliament in which the PML-N would have to team up with its former opponents from the outgoing government led by the PPP.
"(Sharif) needs to solve the issue of terrorism and other problems crippling the economy. If he delivers quickly, fair enough, if not then he will face crisis and criticism," pundit Hasan Askari told AFP.
Chief Election Commissioner Fakharuddin Ebrahim praised the authorities for their cooperation "which enabled us to hold free and fair elections" and recorded a turnout of nearly 60 percent, the highest since 1977.
Both Sharif and Khan won at least one of the seats they had contested, but the PTI, which had promised a "tsunami" of support, quickly conceded defeat.
Asad Omar, a senior PTI leader, sent his congratulations to Sharif's party and said Khan, who is in hospital after falling from a makeshift lift during a campaign rally, was taking the results like a sportsman.
Newly elected PTI member Shaukat Yousafzai said: "It is very clear that PTI has emerged as the largest party in Khyber Pakhtunkhwa, so we will form our government here with the help of like-minded political parties."
Besides the 342-member national assembly, voters also elected four provincial assemblies in Khyber Pakhtunkhwa, Punjab, Sindh and Baluchistan.
Khyber Pakhtunkhwa is a hotbed of militancy. Both Sharif and Khan have vowed to talk to the Taliban and have tapped into the Pakistani public's deep hatred of the US drone war against extremists on the Afghan border.
More than 600,000 security personnel deployed to protect the vote and Pakistan sealed its border with Afghanistan and Iran to boost security after pre-election violence killed at least 127 people, according to an AFP tally.