On May 11, an estimated 60 percent of Pakistan’s 86 million registered voters cast ballots to pick a new government. Election day, like the entire campaign season, was marred by deadly Taliban attacks, mostly at the rallies of avowedly secular parties. And some charges of voter fraud have darkened the proceedings. Still, the election was a democratic achievement worth celebrating: in a country where the military has aborted every democratic transition, this weekend marked the first turnover from one democratically elected government that has served its full five-year term to another.

As expected, the incumbent Pakistan People’s Party (PPP) was routed, effectively reduced to its traditional ethnic stronghold in Sindh province. After five years in power, the PPP government was too tainted by allegations of corruption and poor governance to win the votes of anyone but its most stalwart supporters. In addition, its leadership was virtually unable to campaign in public because of physical threats from the Taliban, which despises the party for supporting the U.S. war on terrorism. Just two days before the vote, armed Islamists allegedly abducted Ali Haider Gilani, the son of former PPP Prime Minister Yousaf Raza Gilani, from an election meeting in his hometown of Multan.

Going into the vote, the X-factor was Imran Khan, the former cricketer-turned-political crusader. During the campaign, he relentlessly demonized the PPP for supporting the U.S. war on terrorism and allowing CIA drones to kill innocent civilians. (Of course, he expediently ignored the fact that those drones were using Pakistani airspace with the Pakistani military’s collusion.) And he promised to wipe clean the slate of status quo parties, even as he cynically recruited their disaffected members to his own party, the Pakistan Tehreek-e-Insaf (PTI). His dazzling promises -- a Pakistan free of corruption within 30 days and of terrorism within 90 days -- were expected to resonate with the Pakistani middle class, which is usually detached from politics. And they did. But not enough where it counted: Punjab, the country’s most politically important province, which holds 148 of the 272 general seats in the national assembly.

In the end, Khan’s biggest victory turned out to be in Khyber Pakhtunkhwa (formerly the North-West Frontier Province), where voters expressed their frustration with the incumbent government by voting it out. PTI far outperformed the incumbent party, the secular Pashtun nationalist Awami National Party, which is blamed for rampant corruption and for failing to curb terrorism. To be fair, the party is itself a victim: the Taliban have killed over 700 of its members, including senior minister Bashir Bilour, who was assassinated in a suicide attack while campaigning in Peshawar in December 2012.

Rejecting both the PPP and the PTI, Punjabis voted en masse for Nawaz Sharif’s center-right Pakistan Muslim League Nawaz, which fought mainly on promises of economic revival. In hindsight, that outcome was not too surprising: with the exception of the southern part of Punjab, the province has been a stronghold of the PML-N since at least the mid-1990s.

Having nearly won an outright majority of seats in the national assembly, Sharif is set to become Pakistan’s prime minister -- his third time at bat. The other two were both brought to an end by the military, one indirectly through a presidential decree in 1993 and the other through the coup led by General Pervez Musharraf in 1999. Imprisoned and then exiled for years after that coup, Sharif appears to have learned the right lessons.

For one, he has publicly opposed any role for the military in politics. He also steadfastly endorsed the previous government’s right to complete its tenure (even as he sided with other opposition parties to build pressure on the PPP to agree to early elections). Similarly, his party supported the PPP’s attempts to pass landmark constitutional and electoral reforms, which were eventually successful.

As an industrialist with a strong base in the business community, Sharif has long been committed to mending fences with India, as a way to both boost trade and reduce the domestic political influence of the military, which has been the main beneficiary of the two countries’ conflict over Kashmir. Finally, Sharif has publicly committed to stopping militant groups from using Pakistani soil as a base for terrorist attacks in India. That includes the Lashkar-e-Taiba, a banned terrorist group that India accuses of orchestrating the 2008 Mumbai attacks and whose alleged ties to the ISI allow it to operate freely in Pakistan.

But critics fear that Sharif is all talk. They argue that the military has already lost its interest in intervening in politics because the generals do not want to take up the thankless task of resolving Pakistan’s myriad economic, political, and security challenges. And in any case, the brass are still smarting from the flak Musharraf’s eight years in power earned their institution. The real test of Sharif’s allegiance to democratic norms, therefore, will not just be how he handles the military but how he deals with his opponents in the PPP and the PTI. How he deals with the media will be another test. After all, his last government is known for trying to muzzle criticism and intimidate journalists. To be sure, the proliferation and growing power of cable news channels since the early 2000s would make it difficult for any government to crack down on press freedoms, even if it wanted to.

Meanwhile, economic revival is easier said than done in a country where military budgets, debt, and waste leave little room for economic development. Some critics also fear that any benefits from liberalizing trade with India might mainly accrue (or be diverted) to the Punjabi industrial and business classes, which are Sharif’s main constituency.

Sharif’s plans to confront terrorism are similarly suspect. Prominent members of his party have made politically expedient deals with Shia-baiting Sunni militant groups, such as the Ahle Sunnat Wal Jamaat. And the outgoing PML-N provincial administration in Punjab was accused of turning a blind eye to the growing persecution of Christians and Ahmadi Muslims. Sharif has also been an advocate of talks with the Taliban. The problem with such talks is that all previous attempts at negotiation have backfired. For instance, the military made several peace deals with the Tehrik-e-Taliban between 2004 and 2009, which did little to curtail militancy. In fact, they emboldened the group to spread outward from its bases in Waziristan into Khyber Pakhtunkhwa. If Sharif and his party are really as friendly to business and investment as they claim to be, they will have to get serious about security to restore domestic and international investors’ confidence.

During his campaign, Sharif raised eyebrows in Washington by reportedly calling for the end of Pakistan’s unpopular involvement in the American-led effort to fight terrorism. But his aides are keen to dispel the impression that he is opposed to cooperating with the United States. They note that Sharif helped the Clinton administration in its efforts to capture Osama bin Laden in the 1990s. And in a post-election press conference, Sharif promised to fully cooperate with the U.S. withdrawal from Afghanistan. There is a caveat, though: according to Sharif’s aides, he is seeking to review the bilateral cooperation agreements struck between the United States and Musharraf’s military government, particularly those relating to drones.

The army might be uninterested in governing directly, but it does still control Pakistan’s foreign policy. And it has its own reasons for being wary of Sharif. When he was prime minister between 1997 and 1999, he took the unprecedented step of firing its chief of staff, General Jehangir Karamat, for criticizing the government and for advocating a formal policymaking role for the military. And military officers are still sore about the fact that he allegedly cultivated numerous loyalists in the senior officer corps. Leaked U.S. diplomatic cables revealed army chief General Ashfaq Pervez Kayani’s intense dislike for Sharif; in March 2009, Kayani was contemplating ousting President Asif Ali Zardari to resolve a moment of political deadlock but he did not want his actions to force an election for fear it could bring Sharif back to power. Some in Sharif’s party, including Shahbaz Sharif, who is Sharif’s brother and the former and presumptive chief minister of Punjab, have tried to reconcile with the army. And for his part, Sharif made it clear after the elections that he has no problems with the military as an institution, only with coup makers.

Besides keeping a meddlesome military at bay, the PML government will have the usual list of daunting problems to deal with, including debilitating power shortages, the nationalist insurgency in Baluchistan, and, above all, international and domestic terrorism, including the ongoing pogrom against Pakistan’s Shia by Sunni militant groups. The high turnout for the election, including the baptism of many middle class Pakistanis as voters, indicates that the public is warming up to democracy. But quick fixes are impossible and higher turnout is a double-edged sword: by virtue of participating, the public has heightened expectations of government performance and probity. And that means that public disaffection could set in rather quickly. Still, if the Sharif government can fend off incursions and at least do better than the PPP, Pakistan’s democracy (and Sharif) will have a real chance to pull through.