Vote-counting began Wednesday in a knife-edge Pakistan general election as former cricket hero Imran Khan sought power on a day marred by a bloody suicide bombing.

Analysts said the vote was too close to call as polls closed at 6:00 pm (1300 GMT), despite widespread allegations of pre-poll meddling in favour of Khan, which saw the process dubbed Pakistan's "dirtiest election".

Gallup Pakistan estimated turnout at between 50 to 55 percent in an electorate of nearly 106 million, similar to the previous contest in 2013.

TV reports showed election workers sorting through massive piles of paper ballots at polling stations across the country.

There were more than 19 million new potential voters, including millions of women and young people.

A suicide bombing in the southwestern city of Quetta, claimed by the Islamic State (IS) group, killed at least 31 people and cast a shadow over voting day.

Hashim Ghilza, a local administration official, said the bomber tried to enter a polling station.

"When police tried to stop him he blew himself up," he told AFP.

Debris, bloodstains and charred vehicles littered the road outside the polling station as the dead and injured were rushed to hospital accompanied by distraught loved ones.

It was the second major attack by IS this month in Balochistan province after an earlier blast at a campaign rally killed 153.

Two-way race

The vote was a rare democratic transition in the populous but poor nuclear-armed Muslim country, which has been ruled by the powerful military for roughly half its history.

The contest largely became a two-way race between Khan's Pakistan Tehreek-e-Insaf (PTI) and the incumbent Pakistan Muslim League-Nawaz (PML-N) of former premier Nawaz Sharif, whose brother Shehbaz is leading its campaign.

Election researcher Azeema Cheema said the contest remained "too competitive to call", with the most populous province of Punjab likely to be the key following fierce campaigning in battleground areas there.

Khan, 65, cast his vote in Bani Gala, a suburb of the capital Islamabad, telling the media it was "time to defeat parties which kept this country hostage for years".

In Lahore, rival Shahbaz Sharif called on Pakistanis to "get out of their homes and... change the fate of Pakistan" before casting his own vote and flashing a victory sign.

But other voters in Lahore, capital of Punjab and traditionally a PML-N stronghold, said they were abandoning the party in favour of PTI.

"I have voted for PML-N my whole life but this time I voted for PTI because Imran Khan has promised free education and health," said 75-year-old Uzma Akram.

Up to 800,000 police and troops were stationed at more than 85,000 polling stations across the country, after a string of attacks targeting political events in the final weeks of the campaign killed more than 180 people, including three candidates.

Earlier, one PTI worker was killed in the northwestern town of Swabi in an exchange of fire with a rival party, police said.