Pakistan voted on Wednesday in a historic general election that was as bitter, heated and bloody as expected following weeks of acrimonious campaigning.

Ex-cricket star Imran Khan held a clear lead in early results on Thursday morning but the count was running painfully slow and well behind schedule. Amid claims of vote rigging, election officials insisted there was “no conspiracy”, blaming technical failures for delaying a result which should have been known by 2am.

Wednesday's vote was marred by a major terror attack in the city of Quetta near the Afghanistan border, where a suicide bomber drove a motorbike into a crowd of people near a polling station. Witnesses told The Independent the target appeared to be a police van, and there were at least five security officers among the 31 dead.

Both the frontrunners had struck confident poses as voting drew to a close on a hot day where tensions often bubbled over between supporters of Mr Khan and the Pakistan Muslim League (PML-N) of jailed former premier Nawaz Sharif.

Imran Khan speaks to journalists after casting his ballot (EPA)

Mr Khan’s opposition PTI campaigned on a message of anti-corruption, while at the same time being accused of enjoying the status of the military’s favoured candidate. With 47 per cent of the vote counted on Thursday morning, PTI led in 113 of the 272 national assembly seats, while PML-N trailed on 64.

More than 350,000 army personnel were deployed across the country to guard polling stations, both inside and out. Most voters The Independent spoke to seemed more grateful for the extra security than intimidated over their choice.

And in Baluchistan’s capital Quetta, it was clear to see why such measures were needed. One witness, Abdul Haleem, was queueing up to cast his own ballot at a school-turned-polling station when he saw a motorcycle drive straight into a crowd of voters. Mr Haleem’s uncle was killed in the blast that followed, he said.

“There was a deafening bang followed by a thick cloud of smoke and dust and so much crying from the wounded people.”

Another witness, Majeed Akbar, said the motorbike seemed to be aiming for the large police presence outside the school. He saw “a cloud of smoke after the blast, it filled the sky and then after that a pool of blood, dead bodies and others injured”.

There was a deafening bang followed by a thick cloud of smoke and dust and so much crying from the wounded people Abdul Haleem, witness

Isis has claimed responsibility for the attack, as it did for the worst single atrocity during the campaign period – also in Baluchistan – when 149 people were killed in a bombing at a political rally.

Elsewhere in the country, scuffles between supporters of rival parties frequently turned violent. Two were killed in separate incidents in Sindh province involving gunfire or firecrackers, and there was a fully fledged gun battle between members of PTI and the secular ANP party in the northern city of Swabi, killing one person and wounding others.

Aftermath footage following deadly blast outside polling station in Quetta, Pakistan

There was anger at many polling stations even where there was no violence, with long queues forming outside many as an inefficient system creaked under the weight of 105 million registered voters. Most predicted turnout to be higher than in 2013, when PML-N won by a margin, but tens of thousands appear to have been turned away as polling booth staff took up to five minutes to process each person.

Despite striking a confident tone, PML-N spokesman Mushaid Hussain told reporters at a news conference that the party had formally applied for voting to be extended by one hour due to the delays “in almost all constituencies”.

Another PML-N coordinator, Muhammad Mendi, said he believed officials were deliberately putting up “hurdles” to block voters adorned with the tiger symbol of Mr Sharif’s party.

PML-N was joined in its call by the third-polling Pakistan People’s Party (PPP), led by Bilawal Bhutto Zardari, the son of former prime minister Benazir Bhutto. The election commission dismissed the request.

And as voting drew to a close, people were driving around Rawalpindi’s roads, waving both PTI and PML-N flags and chanting slogans.

With only 20 minutes left, there was still a small line of women waiting to vote at a university near the Pindi Cricket Stadium.

“God willing, I will still manage to vote,” Iqra, a 20-year-old student, said. This was the first time she was old enough to take part in a general election, and she admitted: “I haven’t decided who to vote for yet; we’ll see once I get inside.” Nevertheless, she thought PTI would win.

Outside, Zubaida Begum, a long-time PML-N supporter in her seventies, was just leaving the polling station.

“I have been voting ever since there have been elections in Pakistan,” she said.

She was adamant that Sharif would be vindicated after the elections and released from jail, where he has just started a 10-year sentence for financial irregularities relating to luxury properties in London, as revealed in the 2015 Panama Papers leak.

“Nawaz Sharif is a very good leader,” Ms Begum said. “Allah will help him. There was absolutely no corruption.”

Supporters of Imran Khan celebrate in Islamabad (Reuters)

Women’s representation has been a major problem at this election, despite the best efforts of the authorities to introduce minimum requirements both for female candidates and female turnout in individual districts.

Just 171 of the more than 12,500 candidates were women, the electoral commission admitted on the eve of the vote, and there were reports from some parts of Khyber Pakhtunkhwa province of women being prevented from voting by traditional local councils.

In Lahore, eight activists from various parties were arrested on suspicion of preventing women voting, after a video circulated on social media showed a long, static queue of female voters outside a polling booth. Mandi Bahauddin, a city official, said the eight were under investigation and “would be charged in accordance with the law”.

Pakistan general election: vote turns violent after suicide bombing Show all 22 1 /22 Pakistan general election: vote turns violent after suicide bombing Pakistan general election: vote turns violent after suicide bombing Pakistani security personnel gather at the site of a suicide attack near a polling station in Quetta AFP/Getty Images Pakistan general election: vote turns violent after suicide bombing A man who was injured in a suspected suicide bomb attack outside a polling station, receives medical treatment at a hospital EPA Pakistan general election: vote turns violent after suicide bombing Polling stations in Pakistan opened for the general election, for around 105 million constituents AFP/Getty Images Pakistan general election: vote turns violent after suicide bombing Pakistani politician Imran Khan, center, chief of Pakistan Tehreek-e-Insaf party, casts his vote EPA Pakistan general election: vote turns violent after suicide bombing Pakistani security officials inspect the scene of a suspected bomb blast outside a polling station, in Larkana EPA Pakistan general election: vote turns violent after suicide bombing A Pakistani woman and her son react after her husband was injured in a suicide attack AFP/Getty Images Pakistan general election: vote turns violent after suicide bombing Voters will have to choose from 11,000 candidates to elect 272 members of the Parliament for the next term REUTERS Pakistan general election: vote turns violent after suicide bombing Cricket star-turned-politician Imran Khan, chairman of Pakistan Tehreek-e-Insaf (PTI), speaks to members of media after casting his vote at a polling station during the general election in Islamabad REUTERS Pakistan general election: vote turns violent after suicide bombing Bilawal Butto Zardari, chairman of Pakistan People Party visits a hospital in Larkana to meet people who were harmed in a blast outside a polling station EPA Pakistan general election: vote turns violent after suicide bombing An election official marks a voters thumb before casting her vote AFP/Getty Images Pakistan general election: vote turns violent after suicide bombing At least 25 people were killed and 30 injured in the incident EPA Pakistan general election: vote turns violent after suicide bombing A polling officer shows empty ballot boxes prior to sealing them, at a polling station, in Peshawar EPA Pakistan general election: vote turns violent after suicide bombing People stand in a line as they wait for a polling station to open in Rawalpindi REUTERS Pakistan general election: vote turns violent after suicide bombing A man who was injured in a suspected bomb blast outside a polling station, receives medical treatment at a hospital in Larkana EPA Pakistan general election: vote turns violent after suicide bombing These elections are the second in Pakistan's history in which a government was able to complete its term to make way for another government after being ruled by military dictators for half of the 71 years of its existence since its founding in 1947 REUTERS Pakistan general election: vote turns violent after suicide bombing A rickshaw carries an electoral flag, as it rides past the mausoleum of Mohammad Ali Jinnah, early morning in Karachi REUTERS Pakistan general election: vote turns violent after suicide bombing Pakistani security officials inspect the scene of a suspected suicide bomb attack outside a polling station during general elections in Quetta EPA Pakistan general election: vote turns violent after suicide bombing A Pakistani soldier checks a voters information AFP/Getty Images Pakistan general election: vote turns violent after suicide bombing An man walks past a wall with electoral posters in Karachi REUTERS Pakistan general election: vote turns violent after suicide bombing A woman shows her thumb marked with indelible ink after she cast her ballot EPA Pakistan general election: vote turns violent after suicide bombing Shahbaz Sharif, second left, President of Pakistan Muslim League Nawaz party which concluded its mandate recently, lines up to cast his ballot EPA Pakistan general election: vote turns violent after suicide bombing Pakistani voters stamp their ballots at a polling station in Rawalpindi AFP/Getty Images

Mr Khan may have received the support of Pakistan’s elite establishments, but observers have been concerned by how he has resorted to a crude populism to extend his appeal more broadly. The 65-year-old has courted the more extreme wings of Pakistan’s religious spectrum by touting the death penalty for blasphemers and vowing to implement an “Islamic welfare state” if he comes to power.

Yasir Yusuf, a 33-year-old chef from the capital’s small and downtrodden Christian minority, said he decided to vote for PTI despite concerns about Mr Khan’s perceived tolerance for extremist Islamist parties.

“We are concerned, but when you are a minority you become meaner; we just think for ourselves,” he told The Independent.

We are too little and this country is too big. I really want to vote for my country, not only for this small minority Yasir Yusuf, Christian voter

“We are too little and this country is too big. I really want to vote for my country, not only for this small minority.”

Asim Majeed, a 24-year-old MBA student, complained of “how slow the people are in there” as he emerged from casting his vote for PTI in Islamabad. He said he believed Mr Khan was different from other leaders.