LAHORE, Pakistan -- Former Prime Minister Nawaz Sharif, once a political exile deposed by the military, returned to the cusp of power Saturday, taking a commanding lead in a parliamentary election in which Pakistanis braved Taliban intimidation to cast ballots with historic prospects for the country's democracy.
Record turnout was reported in several cities, sparked by an energized political campaign dominated by the battle between Mr. Sharif and Imran Khan, the former cricket star whose appeal as an anti-corruption crusader had many predicting that he could play a kingmaker role.
Even with just partial returns in early today, however, Mr. Sharif's party appeared to have secured enough seats to form a government easily. His supporters ran cheering through the streets of Lahore, honking horns and, in some instances, firing bursts of celebratory gunfire.
But while the raucous election highlighted the vibrancy of Pakistani politics, it also highlighted the gaping holes in the country's democracy.
Threats by the Taliban to disrupt voting were borne out in attacks across the country that left at least 21 people dead, including at least 11 in a bombing in Karachi and others in Baluchistan province, where turnout greatly suffered.
Accusations of widespread vote irregularities in Karachi, the nation's largest metropolis, led to the invalidation of results from dozens of specific polling places, Pakistani officials said. Final election results are likely to wait for days.
Even if Mr. Sharif faces no obstacles in forming a government, he will then face a stalled economy, profound infrastructure failure and grave threats from an emboldened Taliban insurgency. Furthermore, he has promised to rein in U.S. influence in Pakistan, leaving questions about the countries' often-stormy relationship.
The election was Pakistan's 10th since 1970 but the first in which a civilian government that has served a full five-year term is poised to hand power peacefully to another elected government.
Unlike previous elections, in which the military's Inter-Services Intelligence Directorate was widely accused of vote manipulation and intimidation, this one offered little evidence of involvement by the military, which has ruled Pakistan directly for more than half its 66-year history.
In what appeared to be a show of support for democracy in Pakistan, the country's most powerful military officer, Gen. Ashfaq Parvez Kayani, went to the voting booth himself instead of mailing in his ballot. His gesture was broadcast live on local TV, the Associated Press reported.
The country was gripped by election fever, most of it driven by the contest between Mr. Sharif and Mr. Khan. In the final days of campaigning, the momentum appeared to be with Mr. Khan, who electrified voters with a series of mass rallies that tapped into a deep vein of support among young and middle-class Pakistanis in urban areas.
His ratings rose further after he fell nearly 15 feet to the ground at a rally in Lahore on Tuesday, badly injuring his back but winning widespread public sympathy.
But as the results flooded in late Saturday, and television projections gave Mr. Sharif up to 119 of the 268 elected seats on offer, against just 33 for Mr. Khan, promises of a revolutionary "tsunami" led by the former cricket player appeared to have vanished.
That result signaled a victory of sorts for old-style dynastic politics: The Sharifs have dominated Punjab, Pakistan's most populous province, since the 1980s and have cultivated voters for the past five years through development projects financed by the provincial government, which they controlled.
The other loser was President Asif Ali Zardari's Pakistan Peoples Party, which led the last government but now seems destined to the opposition benches. Mr. Khan, however, was poised to capture a valuable consolation prize, one with potentially sharp implications for U.S. policy: control of the provincial government in Khyber Pakhtunkhwa along the Afghan border.
During his campaign rallies, Mr. Khan stridently said he would end CIA drone strikes in the tribal belt, by ordering the Pakistani military to shoot down U.S. aircraft if necessary. He has said he believes Pakistan should negotiate with Taliban insurgents, not fight them.
Still, it is Mr. Sharif who is likely to have the greatest impact on relations with the United States. A nationalist by inclination, Mr. Sharif, while publicly amenable to reaching out to the U.S., has also hinted that he was open to negotiating with Taliban rebels in the northwest -- a stance that would greatly concern U.S. officials as they try to withdraw from an Afghan war next door that has featured many cross-border attacks by those insurgents.
The election evoked a rare sense of enthusiasm for politics in Pakistan. About 4,670 candidates fought for 272 directly elected seats in Parliament, while almost 11,000 people battled for the four provincial assemblies. Aside from more traditional politicians, they included astrologers, openly transgender candidates, former models and the first female candidates in the tribal belt along the Afghan border.
Also running were dozens of candidates from Sunni sectarian groups, some with links to violent attacks on minority Shiites.
In a statement Friday, the Taliban leader Hakimullah Mehsud ordered his commanders to attack the "infidel system" of democracy, warning that teams of suicide bombers would hit targets across the country.
At least 21 people were reported killed in attacks across Pakistan on Saturday, among them a gunfight and an attack on a polling place in the western province of Baluchistan and two explosions in the northwest, including in Peshawar, that injured several people. The deadly bombing in Karachi appeared to have been directed at a candidate from the Awami National Party, one of three secular-leaning parties that have borne the brunt of Taliban attacks that have killed at least 125 people in the past month.
The police had established new checkpoints and military helicopters patrolled the skies in Peshawar, the city that has been worst hit by militant violence over the years. Hospital workers were put on alert while billboards across the city asked people to watch for suspicious activity.