For two Pakistani doctors languishing in jails thousands of miles apart, there was more at stake than the promise made by Imran Khan to transform their nation as he declared victory after the general election.

During weeks of frenetic political campaigning, an influential group of British Pakistanis has been negotiating with Khan and senior military figures to arrange a prisoner swap involving Dr Shakil Afridi, who helped the CIA track the al-Qaida leader, Osama bin Laden, and Dr Aafia Siddiqui, convicted of attempting to kill two American military personnel.

While on the election trail, Khan, who heads the Tehreek-e-Insaf party which won the largest number of seats, and is due to be sworn in as prime minister on 11 August, announced that he would secure Siddiqui’s repatriation. The initiative to achieve this is being led by a British peer, Nazir Ahmed, who is to visit Pakistan soon for discussions with the powerful military leadership, which is likely to have the final say. Ahmed, who is closely connected to the Pakistani establishment, said: “The Americans are desperate for the release of Dr Afridi and to take him to their country, while the Pakistani public want Dr Siddiqui to come home. There have been some very positive developments in our discussions with the Pakistani military leadership. They are very receptive to the idea of striking a deal with the Americans and so is Pakistan’s political leadership. They actually came close to it a while ago but it fell through because of other factors. It’s just a question of timing, but I’m very confident that an exchange can be arranged.”

Siddiqui, 46, is being held at FMC Carswell in Fort Worth, Texas, a federal prison for those with mental health needs, after being sentenced to 86 years’ imprisonment in 2010. The Americans accused her of being an al-Qaida “facilitator” who was plotting attacks in New York. For five years before her arrest in 2008, they alleged that they did not know of her whereabouts, declaring her one of the world’s most-wanted terrorists.

Afridi, 56, was sentenced in 2013 to 33 years’ imprisonment for treason. He ran a bogus hepatitis B vaccination campaign for the CIA in the Pakistani city of Abbottabad, collecting DNA samples that allowed it to locate Bin Laden, but was charged with other terrorism-related offences. His sentence was later reduced to 23 years, which he is appealing against from prison in Rawalpindi, near Islamabad.

The incarcerations have damaged US-Pakistan relations, while generating anger within both nations. Siddiqui’s conviction brought protests across Pakistan. The Americans hailed Afridi as a hero.

Naseem Bajwa, a barrister who practises in London and Lahore, said: “The ball is in Pakistan’s court because the Americans at the very highest levels want Afridi. The legal mechanism exists for a prisoner swap so it’s just a case of nailing down the political and military backing for it in Pakistan, which is now there.”

Siddiqui’s family and supporters claim the case against her is fabricated and that she was kidnapped by Pakistani intelligence while driving through Karachi in 2003 with her three children. They allege she was handed over to the Americans and held in solitary confinement at the Bagram base in Afghanistan, which accounts for her “missing” five years, during which she was tortured, raped and suffered mental illness.

Siddiqui, a neuroscientist, who also holds American citizenship, is not appealing against her conviction, protesting that she will not get a fair hearing. US officials say Afridi’s imprisonment is a “priority issue”.