The parties of former prime minister Nawaz Sharif and cricketer-turned-politician Imran Khan appeared to be well ahead of their rivals in Pakistan's election, according to a partial count of votes cast on Saturday.
The election, in which 86 million people were eligible to vote, will bring the first transition between civilian governments in a country ruled by the military for more than half of its turbulent history.
Despite pre-election violence, and attacks on Saturday which killed at least 17 people, millions turned out to vote.
The partial count showed that while Sharif was in the lead, his party could lose 15 of its seats in the critical province of Punjab to Khan, whose emergence on the political stage has up-ended a system dominated by two parties.
Television channels showed Khan's party was ahead in more than 50 of the 272 seats in the election.
Khan, Pakistan's best-known sportsman who led a playboy lifestyle in his younger days, is seen by many as a refreshing change from the dynastic politicians who long relied on a patronage system to win votes.
His Tehrik-i-Insaf (PTI) appeals mostly to young, urban voters because of his calls for an end to corruption, a new political landscape and a halt to U.S. drone strikes on Pakistani soil. About one-third of the country's population is under the age of 30.
Sharif's party, the Pakistan Muslim League - Nawaz (PML-N), looked set to win the most seats in parliament but Khan could deprive it of a majority and dash Sharif's hopes of a return to power 14 years after he was ousted in a military coup, jailed and later exiled.
The strong performance of Sharif and Khan will likely deal a blow to the outgoing Pakistan People's Party (PPP), placing it third.
Power in Pakistan has for decades alternated between the PML-N and the PPP, whose most prominent figure is President Asif Ali Zardari, widower of assassinated former premier Benazir Bhutto.
Opinion polls have suggested that disenchantment with the mainstream parties could mean that no one group emerges with a parliamentary majority, making the next government unstable and too weak to push through much-needed reform.
Voters were electing 272 members of the National Assembly. To win a simple majority, a party would have to take 137 seats.
However, a further 70 seats, most reserved for women and members of non-Muslim minorities, are allocated to parties on the basis of their performance in the contested constituencies. To have a majority of the total of 342, a party would need 172.
Pakistan's Taliban, who are close to al Qaeda, have killed more than 120 people in election-related violence since April. The group, which is fighting to topple the US-backed government, regards the election as un-Islamic.
More bloodshed marred election day. A bomb attack on the office of the Awami National Party (ANP) in Karachi killed 11 people and wounded about 40. In Baluchistan, four died in a gunbattle and elsewhere gunmen on a motorcycle opened fire near a polling station, killing two people, police said.
Despite the searing heat, many went to the polls excited about the prospect of change in a country that is plagued with Taliban militancy, a near-failed economy, endemic corruption, chronic power cuts and crumbling infrastructure.
"The team that we elect today will determine whether the rot will be stemmed or whether we will slide further into the abyss," prominent lawyer Babar Sattar wrote in The News daily.
Despite Pakistan's history of coups, the army stayed out of politics during the five years of the last government and threw its support behind Saturday's election. It still sets the nuclear-armed country's foreign and security policy and will steer the thorny relationship with Washington as NATO troops withdraw from neighbouring Afghanistan in 2014.
However, some fear the military could step back in if there is a repeat of the incompetence and corruption that frustrated many Pakistanis during the last government.
Power cuts can last more than 10 hours a day in some places, crippling key industries like textiles, and a new International Monetary Fund bailout may be needed soon to rescue the economy.