* Khan makes last-minute gains
* Tough negotiations over government expected
* Sharif remains front-runner
Former Pakistan cricket star Imran Khan's party was enjoying a late surge of support on Friday, the eve of a landmark election, raising the prospect of a fragmented parliament that could lead to weeks of haggling to form a coalition government.
The failure of the major parties to capture a commanding lead raises the risk a weak government will emerge, clouding optimism over the first transition between civilian governments in a country that has been ruled by the military for more than half its history.
The party of former prime minister Nawaz Sharif looks set to win the most seats, returning Sharif to power 14 years after he was ousted in a military coup, imprisoned and later exiled.
But Khan could end up holding the balance of power if there is no clear-cut winner. In a sign of his popularity, 35,000 supporters turned up on Thursday at a rally in Islamabad that he didn't even attend.
The 60-year-old is in hospital after suffering injuries in a fall from a mechanical lift at a rally this week, which may also win him sympathy votes.
"While Khan was initially handicapped by the lack of party organisation and the absence of a formal presence at the provincial level, he managed to overcome these challenges by establishing a network of volunteers who have campaigned frenetically and held massive public rallies in recent weeks," said Shamila Chaudhary, senior editor at Eurasia Group.
Khan, Pakistan's most well-known sportsmen who led a playboy lifestyle in his younger days, has emerged as a tough challenger to dynastic politicians who have relied heavily on a patronage system to win votes and are often accused of corruption.
Campaigning officially ended at midnight on Thursday. Election-related violence that has killed more than 110 people continued on the eve of the vote.
Five people were killed in bomb attacks on party offices on Friday, one in Quetta, capital of the southwestern province of Baluchistan, and the other in the northwestern city of Peshawar.
The al Qaeda-linked Pakistan Taliban, which regards the elections as un-Islamic, are responsible for the attacks that have made this the country's bloodiest election yet, and on Thursday they revealed plans for suicide bombings on polling day.
The militants have mostly targeted the more secular-leaning parties in the outgoing coalition led by the Pakistan People's Party (PPP), severely restricting their ability to campaign.
The bombers have largely spared the more conservative parties that have voiced doubts about Pakistan's participation in the U.S.-led campaign against militancy, including those of both Khan and Sharif.
Pakistanis say they will still vote, despite the bloodshed.
"I will vote for Imran Khan because he is a symbol of change," said student Waqas Ali. "We have tested other leaders several times but they are useless. I will go to the polling station despite serious threats of terrorism."
"FRACTURED MANDATE" WARNING
Voters will elect 272 members of the National Assembly and to win a simple majority, a party would have to take 137 seats.
However, the election is complicated by the fact that 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.
Khan, who appeals mostly to young, urban voters, has won support by calling for an end to corruption, a new political landscape and a halt to U.S. drone strikes on Pakistani soil.
Early opinion polls had put the share of votes for Khan's Tehrik-i-Insaf (PTI) party as low as single figures.
However, a survey released on Wednesday showed 24.98 percent of voters nationally planned to vote for his party, just a whisker behind Sharif's Pakistan Muslim League (PML-N).
The Herald magazine poll showed Sharif's party remained the front-runner in Punjab, which, with the largest share of parliamentary seats, usually dictates the outcome of elections.
It also pointed to an upset for the PPP placing it in third place. Politics have long been dominated by the PML-N and the PPP, whose co-chairman is President Asif Ali Zardari, widower of assassinated former prime minister Benazir Bhutto.
"The PPP didn't take care of the poor masses and always engages in corrupt practices whenever they come to power," said Sher Nabi, a banker from Peshawar.
"So we've decided to vote for the PTI candidate this time and test Imran Khan to see if proves as honest as he claims."
The army has vowed to stay out of politics but has never enjoyed warm relations with the PPP, which has a long record of opposition to military involvement in government.
Some analysts say the preferred election outcome for the army would be a parliament where no one party holds a majority, with the balance of power held by Khan. Analysts say the military see Khan as a useful foil to the main parties.
Sharif, who was prime minister twice in the 1990s, has said he would reconsider Pakistan's support for the U.S. war on Islamist militancy and promote free-market economics if he won.
He has warned that any coalition politics would paralyse policy-making.
"Whichever party wins, it needs to have a very clear majority for it to have the necessary policies to deal with the serious challenges the country faces, for the state to have a strong writ," he told the Dawn newspaper.
"A fractured mandate, a split mandate, would be worse than the last five years."
While the outgoing PPP made history by becoming the first civilian government to serve a full five-year term, it failed to tackle a dizzying array of problems.
The economy is feeble and may need another International Monetary Fund bailout to stay afloat. Chronic power cuts can last more than 10 hours a day in some places, crippling key industries like textiles and enraging ordinary people.
After months of campaigning, political parties may now become enmeshed in negotiations that might only delay the huge task of putting the nuclear-armed country on the right track.
"While a hung parliament is a possibility given the expected fractured outcome of polling, it is the least desirable outcome for all parties," said analyst Chaudhary.
"It would lead to an unstable minority government that could conceivably be led by PML-N, PPP, or even PTI, inevitably leading to another round of elections that, given physical and financial requirements, the full range of parties would rather avoid."