ISLAMABAD: It was targeted by the Taliban, women and minorities were vastly under-represented, and videos of irregularities went viral online – yet Pakistan's 2013 election may still have been its fairest ever.
A much improved voter roll, near-record turnout, and vigilant citizens tweeting alleged rigging all played their part in what former Norwegian PM and election observer Kjell Magne Bondevik called "a credible expression of the will of the people".
Saturday's election saw about 50 million Pakistanis vote, with former prime minister Nawaz Sharif emerging the winner nearly 14 years after he was deposed in a coup.
It represented the first time a civilian government was to hand over power to another, in a country where sporadic attempts at democracy have been interrupted by three coups and four military rulers.
Violence in the run-up to polls and on election day itself killed more than 150 people, according to an AFP tally, as the Taliban set their sights in particular on secular parties that made up the outgoing government.
But despite the threat, nearly 60 per cent of the country's registered 86 million voters went to the polls, moving Pakistani columnist Murtaza Haider to hail his country as "the world's bravest democracy".
"The results of May 11 elections prove once again that if given the opportunity, Pakistani masses would embrace democracy against the religious orthodoxy," he wrote in Dawn newspaper.
The process was far from perfect. Eleven million fewer women voted than men, with militant threats and social conservatism excluding them altogether in parts of the northwest and tribal areas, including the Taliban stronghold of North Waziristan.
Yet overall women's participation was higher than ever, particularly in urban areas, and almost three times as many women ran for office as in 2008.
"The main thing was serious interest in the election and we have a very heavy participation by women everywhere. So I think this was a good election," said IA Rehman, a veteran human rights activist.
Some of the credit goes to Pakistan's database authority, which oversaw an increase in the registration of women from 50 per cent during the last polls to 86 per cent by adding all adults with an ID card to the voter roll.
The agency culled the dead from the electoral roll, and clamped down on ID card fraud that resulted in some people voting dozens of times in the last election.
It put in place measures that allowed polling stations to access would-be voters' photographs and even check thumb impressions against the national database in cases of suspected fraud.
The agency also allowed voters to SMS their ID card number to instantly find which polling station they should use – a serviced accessed 55 million times.
"Technology has strengthened democracy in Pakistan, enhanced turnout, eroded corruption and enhanced transparency," Tariq Malik, chairman of the National Database Registration Authority, told AFP.
But he warned that technology can only do so much and poll officials remained susceptible to corruption.
As in previous elections, allegations of fraud were made around the country, with particular focus on claims by Imran Khan's Pakistan Tehreek-e-Insaf (PTI) in Karachi and Lahore.
Activists posted pictures on Twitter of ballot papers thrown out on the street, and videos of alleged voter intimidation were broadcast on TV and went viral on social media.
But the attention these allegations received could have been instrumental in the ordering of a re-poll in 43 polling stations in Karachi, which was lauded by a European Union observers' mission.
"People are better informed and don't only rely on officials giving them news. Smart phones were a weapon for everyone, as people put up pictures in real time," said Qurratulain Zaman, director of NGO BytesForAll which live-tweeted alleged rigging using the handle @pakvotes.
There is still a long way to go.
More than 200,000 people from the persecuted Ahmadi community boycotted the election in protest at having to vote as minorities and not Muslims. And turnout was very low in restive Balochistan province.
But Rehman said there was much to take heart from.
"The systematic disruption of the electoral process did not happen as it used to in the past," he said.
"The way people turned out they displayed their commitment to democracy, their faith in democracy and electoral politics.
"There was such a push by religious parties who kept saying, 'Don't vote don't go to the vote.' The people ignored all these things and took part."
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ