Pakistan politics: Key players
Pakistan's civilian governments have often been at loggerheads with the judiciary and military, who are frequently accused of meddling in a country with a history of coups. Here are the main players in the country's politics.
Nawaz Sharif - set to be new PM
Twice Prime Minister Nawaz Sharif is heading for a record-breaking third term in office after a remarkable political comeback. Toppled by the military in 1999, jailed and then exiled, he returned to the country for elections in 2008 before patiently biding his time in opposition.
His Pakistan Muslim League-N (PML-N) remains the main political force in Punjab, the most populous province of Pakistan, having fought off a challenge from the revitalised party of Imran Khan. Mr Sharif was tipped to win, but the margin of his victory has surprised many. No stranger to corruption allegations himself, Mr Sharif has ridden a wave of anger against the perceived corruption and inefficiency of the outgoing PPP government.
A wealthy industrialist, he is seen as pro-business - one of the most pressing tasks he now faces will be sorting out an economy in crisis. Neighbouring countries have welcomed his win - it means a more stable government in Pakistan - although many Afghans in particular still view him with suspicion.
Mr Sharif will have to deal with Pakistan's security crisis and efforts to end war over the border in Afghanistan. He denies being soft on militants - but critics say he tolerates religious extremism. Pakistanis may remember how unpopular he was before the coup, when many saw him as power-hungry. Voters hope he is now older and wiser.
Correspondents say once in power Mr Sharif may have to accept the army view that there is no option but to fight militants who attack domestic targets.
President Asif Ali Zardari
One of Pakistan's most controversial political figures, Asif Ali Zardari is often considered something of an accidental president. He came to power in September 2008 on a wave of public sympathy following the assassination of his wife, former Prime Minister Benazir Bhutto. But his term in office - due to end in September 2013 - has been one of unrelenting political and social turmoil, growing instability and persistent allegations of corruption and economic mismanagement.
His Pakistan People's Party was trounced in the 11 May vote and he now faces a period of awkward cohabitation with his rival Nawaz Sharif as prime minister. Under Mr Zardari's leadership Pakistan's relationship with Washington deteriorated, with the US questioning whether Islamabad was doing enough to tackle militancy.
The career of Mr Zardari - nicknamed Mr Ten Percent - has been dogged by corruption allegations. The Supreme Court has been pushing to reopen a corruption case for which he has already spent eight years in prison. He is increasingly unpopular with the Pakistani public. Health problems have seen him travel abroad for treatment at crucial moments.
Another test for his leadership came in late 2011 with the leaking of the memo asking for US help to avert a possible coup, following the killing of Osama Bin Laden earlier that year. Mr Zardari denied involvement in the "memogate" scandal, and appears to have escaped possible impeachment at least until the end of his time in office.
Imran Khan - opposition leader
The former international cricketer has been on the political scene for years, but struggled to make any significant gains until now. He won his Pakistan Tehreek-e-Insaf (Movement for Justice) party's only seat in 2002, and he boycotted the 2008 elections.
In the last couple of years, Mr Khan has tried to bolster his popularity by riding a wave of disillusionment, particularly among the urban middle class and young voters. He sought to capitalise on anger against US drone strikes in Pakistan's tribal areas. He also succeeded in winning the support of some politicians who had grown disgruntled with their own parties, which helped counter accusations of political inexperience.
One of the main promises of Mr Khan's change agenda was to sweep away the rampant corruption plaguing Pakistani politics, in part by calling for an end to foreign aid. But correspondents cautioned he had some way to go to turn popular support into electoral gains. He is, however, believed to be popular with the military.
In the end all the rallies and Mr Khan's high profile failed to produce the "political tsunami" he predicted on 11 May. However, his party could emerge as second largest nationally and may lead the government in Khyber Pakhtunkhwa province, which is plagued by a conflict between security forces and militants.
Gen Ashfaq Kayani - army chief
As military chief, Gen Kayani has presided over one of the most turbulent periods in Pakistan's military history, with the killing of Osama Bin Laden by US forces on Pakistani soil, the growing threat of terror attacks and widespread public anger at US drone strikes which have resulted in the deaths of civilians as well as militants.
In January 2013 he was publicly criticised by a leader of the minority Shia community for what he said was the army's failure to protect them from a series of sectarian attacks that killed almost 100 people.
Gen Kayani pushed for an investigation into the "memogate" affair, saying the alleged note was a conspiracy against the army. In return, he was accused by the government of acting unconstitutionally.
Pakistan's military has carried out three coups in the past but analysts say the military has little to gain from mounting another - it has its hands full with the fight against Islamist militants and such a coup would attract strong international criticism. Gen Kayani is due to step down in November.
Mohammad Iftikhar Chaudhry - chief justice
Pakistan's chief justice has form in opposing the sitting government. He was one of several judges sacked by Gen Pervez Musharraf in 2007 after they questioned his right to remain in office. A long campaign was launched and he was finally restored to his post in March 2009.
For a time Iftikhar Chaudhry had a strong populist image, seen as a champion of the rule of law, praised as the only judge in history to have stood up to a military ruler and won. But he has been accused of being selective in the cases he pursues.
In June 2012 Mr Chaudhry found himself in the embarrassing position of having to exclude himself from the bench hearing allegations of corruption made by a business tycoon against his son, Arsalan.
The chief justice initiated the case as a response to accusations that Arsalan had accepted millions of dollars in bribes. Both he and his son deny any wrongdoing.
The Supreme Court has historically given legitimacy to military coups and some say he has dragged his feet over corruption allegations against the intelligence service while pursuing those against the government.
The court has not only arbitrated on the "memogate" scandal but in 2012 it disqualified Yousuf Raza Gilani as prime minister for refusing to pursue corruption charges against President Zardari. Along with the president and army chief, Mr Chaudhry is due to exit the stage later this year. He is to step down in December.
Zaheerul Islam - intelligence chief
Lt Gen Zaheerul Islam replaced Ahmad Shuja Pasha as head of the Inter-Services Intelligence (ISI) spy agency in 2012.
He took up the post after a tumultuous year in which the agency was accused by the US of backing militants across the border in Afghanistan.
Pakistan has consistently denied such claims but relations with the US have been tense.
Upon assuming office, he had to deal with the fallout of the Bin Laden killing - in which some in the US accused Pakistan's establishment, and especially the ISI, of at best incompetence and at worst complicity after the al-Qaeda chief was found to have lived in the country for a number of years.
Lt Gen Islam was born into a military family and is the army commander in Karachi. He has also served as deputy head of the ISI in the past.
Many believe the ISI head could be an important figure in any future Pakistani peace negotiations with the Afghan Taliban.
Pervez Musharraf - former military leader
Pakistan's last military leader dramatically returned in March 2013 to compete in elections, ending four years of self-imposed exile and defying death threats.
But it seems it was a strategic mistake to do so, because he now faces trials in at least four criminal court cases, including a possible charge of treason. Whether the new government chooses to pursue that charge is not yet clear.
In one case, he is accused of failing to provide adequate security for former Prime Minister Benazir Bhutto, which contributed to her assassination in 2007.
As president from 2001 to 2008, Pervez Musharraf was one of Pakistan's longest-serving rulers. But he was barred from standing in 2013 and his All Pakistan Muslim League (APML) performed as badly as many predicted it would.
The military is thought to be viewing his predicament with a degree of concern, aware that his case could set a precedent.