Pakistan will make history on Wednesday when the country goes to the polls to elect a new government, the first time it will ever have achieved a second democratic transition of power in a row.

Yet while that should be being hailed as an unprecedented landmark of stability for the nation, there are warning signs to be found in a campaign that has been one of the most dangerous and distasteful in modern history.

With the ousted prime minister and former leader of one of the two main parties, Nawaz Sharif, in jail on corruption charges, the narrow favourite appears to be former cricket legend and playboy Imran Khan.

From social media to the streets, the vicious nature of the campaign has polarised Pakistani society into supporters of Mr Khan’s Pakistan Tehreek Insaf (PTI) party, and the incumbent Pakistan Muslim League – Nawaz (PML-N) of Mr Sharif.

But with the two main parties doing anything they can to sully each other’s reputations, it is also possible neither will prove popular enough to win outright. The left-leaning Pakistan People’s Party, led by the son of assassinated former leader Benazir Bhutto, should stand ready to play kingmaker in third place – but adding to the chaos, PPP has already ruled out a coalition with either main party.

It has also been an exceptionally violent buildup to Wednesday’s vote. Since campaigning began, around 200 people – four of them candidates – have lost their lives in terrorist attacks.

Mr Khan has painted himself as the change candidate, and used Mr Sharif’s jailing over the ownership of luxury property in London to frame PTI as the anti-corruption party.

But he is also favoured by conservatives and the military, and Mr Sharif has accused the country’s immensely powerful generals of “pre-rigging” the election in PTI’s favour. He says they also had a hand in his conviction and 10-year sentence.

Speaking to The Independent in Islamabad, PML-N central media coordinator Muhammad Mandi said the party was “ready for a landmark election”. “Our workers are charged, our voters are ready to get out and vote and we issue a warning to the authorities concerned, that we will not tolerate any rigging.”

Party members have been told to be “watchdogs” of the vote, casting their own ballots before going on to watch the process of counting and the retiring officers for any irregularities.

Mr Mandi said the Pakistani nation had widely accepted Mr Sharif’s narrative of “respect the vote”, which paints the military, courts and conservative establishment as anti-democratic. “No one can stop the PML-N winning the general election on Wednesday,” he said.

PTI’s spokeman Asad Umar claimed the party was ahead “in all opinion polls”. “On 25 July, the people of Pakistan will defeat the corrupt mafia and Imran Khan will be the new prime minister,” he said. Mr Umar described the rigging charges from PML-N as “baseless and nonsense”. “After the arrest of Nawaz Sharif they are nervous, and they want to make the election controversial,” he said.

In a pre-election assessment report, an independent think tank called the Pakistan Institute of Legislative Development and Transparency (Pildat) said there was little doubt there had been attempts at what has been dubbed “pre-rigging”.

According to its own modelling, the two parameters that have depreciated the most since Pakistan’s last election were the perception of neutrality of the military towards political parties and candidates, awarded the lowest score of 33.4 per cent, followed by the perception of freedom of private media from the influence of state institutions and vested interests, receiving a score of 37.8 per cent.

Ahmed Bilal Mehboob, president of Pildat, said: “It is a fact that all mainstream parties are complaining about pre-poll rigging, and the mainstream public are not happy with the way the election campaign has been run.

“In the history of Pakistan we have not had many elections about which we can say they were free and fair,” he said. “Now we have to see whether the pre-election rigging will fulfil the objectives of the establishment of Pakistan, and what the fallout will be if it does not.

“I am afraid that [neither] mainstream political parties will accept the results,” he added.

The chief election commissioner (CEC), retired Justice Sardar Muhammad Raza, on Tuesday assured voters that the Election Commission of Pakistan (ECP) was “trying its best to hold free, fair and unbiased elections”.

In a video message released by the election body, Mr Raza urged voters to fulfil their “duty towards the nation” by casting their votes calmly and responsibly on polling day.

Polling begins at 8am local time, and concludes at 6pm. While one side or the other might claim victory as early as Wednesday night, official results could take up the three days to tally.

Transgender in Pakistan Show all 16 1 /16 Transgender in Pakistan Transgender in Pakistan Dancing at Shakeela's party, an event to celebrate a transgender life in middle-age Reuters Transgender in Pakistan Venue staff members watch people dance at Shakeela's party in Peshawar, Pakistan Reuters Transgender in Pakistan Security searches guests as people arrive at Shakeela's party in Peshawar, Pakistan Reuters Transgender in Pakistan Members of the transgender community dance at Shakeela's party in Peshawar, Pakistan Reuters Transgender in Pakistan Shakeela, a member of the transgender community, works in the kitchen at home in Peshawar, Pakistan Reuters Transgender in Pakistan 'It's the first time a transgender party has been held openly,' says activist Farzana Jan Transgender in Pakistan Farzana Jan, a member of the transgender community, poses for a photographer ahead of Shakeela's party in Peshawar, Pakistan Reuters Transgender in Pakistan Guests at Shakeela's party Reuters Transgender in Pakistan Money thrown by the guests is used by people to help them start a new business or project Transgender in Pakistan Rani smiles from behind her make-up as she prepares for the party Reuters Transgender in Pakistan Shakeela resting at her home in Peshawar Reuters Transgender in Pakistan A photo hangs on the wall in the home of members of the transgender community in Peshawar, Pakistan Reuters Transgender in Pakistan Make up lies on the floor as members of the transgender community prepare for Shakeela's party in Peshawar, Pakistan Reuters Transgender in Pakistan A guest counts money she plans to throw at Shakeela's party Reuters Transgender in Pakistan Bubbly helps Shakeela with her dress as members of her own family watch on Reuters Transgender in Pakistan Chahat, a member of the transgender community, prepares for Shakeela's party in Peshawar, Pakistan Reuters

There are positive landmarks to be found aside from the flurry of recriminations. For the first time in history, five trans candidates will be standing for election, and there are also a record 171 women in the running, though they make a small minority of the 12,500 candidates vying for national and provincial seats across the country.

Nonetheless, there will be a huge security presence trying to maintain order on the streets on Wednesday, with approximately 800,000 law enforcement and army personnel deployed.

Of more than 85,000 polling stations across the country, around 17,000 have been declared “highly sensitive” and will receive special security measures.

The majority of these – more than 11,000 – were in the populous Punjab and Sindh provinces, where the election is expected to be won or lost. Rights activists have also expressed concern that soldiers will be positioned inside booths where votes are cast.