Lahore, Pakistan - Violence has marred a knife-edge election in Pakistan, where a suicide bomb blast killed at least 31 people in the southwestern city of Quetta, as millions of voters took to the polls to elect a new government.

The bomber targeted a police vehicle in the provincial capital of Balochistan province, wounding at least 40 others, said senior police official Aitzaz Goraya.

Incidents of firing and grenade attacks on polling stations were also reported elsewhere, including the Khuzdar district in Balochistan and Larkana in Sindh province.

The incumbent Pakistan Muslim League-Nawaz (PML-N) is looking to fight off a challenge by the opposition Pakistan Tehreek-e-Insaf (PTI), led by cricketer-turned-politician Imran Khan.

The Pakistan People's Party (PPP), with young scion Bilawal Bhutto Zardari at its helm, is also competing nationally, along with other parties.

More than a 105 million Pakistanis were eligible to vote in the general election, which saw thousands of candidates competing for 272 seats in the lower house of parliament, as well as 577 provincial assembly seats.

The ruling PML-N was dealt several blows in the run-up to the polls, seeing dozens of defections, as well as the conviction and arrest of its former chief, Nawaz Sharif, for corruption earlier this month.

Punjab remains key

Punjab, the country's most populous province, holds 141 of the country's 272 directly elected seats, and the key to forming the government.

As polls closed, but before results came in, jubilant supporters of both the PML-N and PTI drove their the streets of the city, waving flags and happily shouting their party's slogans.

"I was going to vote for Nawaz Sharif, but the way that he lied on the floor of the House, that convinced me that I couldn't vote for him," said Ahmed Ali Malik, a retired banker who flew in from Manchester in the UK to vote at Lahore's Delhi Gate.

Elsewhere, anger with the alleged conspiracy to unseat the PML-N was apparent among some voters.

"Now the army, the intelligence agencies and the judiciary are taking sides," said PML-N voter Tariq Ateeq Sheikh, 50, a property dealer in Lahore's Walton neighbourhood.

"They've become touts for the PTI."

PML-N alleges that the country's powerful military - which has ruled Pakistan for roughly half of its 70-year history and has often sparred with Sharif over control of security and foreign policy - is behind a campaign that has tilted the electoral playing field in favour of Khan's PTI.

On July 16, the Human Rights Commission of Pakistan (HRCP), an independent rights watchdog, decried "blatant, aggressive and unabashed attempts to manipulate the outcome of the upcoming elections".

It also documented widespread censorship of the news press, in line with allegations that the military had intimidated journalists when reporting on politics and security issues.

Men stand in line to cast their vote during the general election, outside a polling station in Peshawar [Fayaz Aziz/Reuters]

'We are free from the terror'

In the southern city of Karachi, a sprawling metropolis of more than 18 million, voters came out in droves.

The city is now seen as politically open for the first time in three decades, with the grip of the previously dominant Muttahida Qaumi Movement (MQM) loosening.

In 2013, paramilitary forces launched a targeted operation against the party's alleged criminal enterprises, jailing dozens and causing the party to split into several factions.

In the PECHS neighbourhood, voters said they felt free for the first time in years.

"We are free from the terror we have lived under for the last 35 years," said Muhammad Anwar. "People are coming out to vote themselves. In the past, our votes were cast [on our behalf]."

Daniyal Raji, 23, said he had been forced to vote for the MQM in the last election, but was backing Khan's PTI this time around.

"[In 2013], my hand was held and made to stamp the kite symbol [the MQM's electoral symbol]," he alleged.Asked who he was voting for this time around, Raji was clear: he was voting for "change", and the PTI.

A woman votes during the general election in Karachi, Pakistan [Akhtar Soomro/Reuters]

With additional reporting by Alia Chughtai in Karachi and Saadullah Akhtar in Quetta.