ISLAMABAD, PAKISTAN — Former Pakistani Prime Minister Nawaz Sharif declared victory following a historic election marred by violence Saturday, a remarkable comeback for a leader once toppled in a military coup and sent into exile.

The 63-year-old Sharif, who has twice served as premier, touted his success after unofficial, partial vote counts showed his Pakistan Muslim League-N party with an overwhelming lead. The party weathered a strong campaign by former cricket star Imran Khan that energized Pakistan’s young people.

Sharif expressed a desire to work with all parties to solve the country’s problems in a victory speech given to his supporters in the eastern city of Lahore as his lead in the national election became apparent based on vote counts announced by Pakistan state TV.

The results, which need to be officially confirmed, indicated Sharif’s party has an overwhelming lead but would fall short of winning a majority of the 272 directly elected national assembly seats. That means he would have to put together a ruling coalition, which could make it more difficult to tackle the country’s many problems.

“I appeal to all to come sit with me at the table so that this nation can get rid of this curse of power cuts, inflation and unemployment,” Sharif said.

Despite attacks that killed 29 people, Pakistanis turned out in huge numbers Saturday to vote in an election that marked a historic democratic transfer of power in a country plagued by military coups.

The heavy voter turnout signaled a yearning for change after years of hardship under the outgoing government.

It also offered a sharp rebuke to Taliban militants and others who have tried to derail the election with attacks that have killed more than 150 people in recent weeks.

The vote marked the first time a civilian government has completed its full five-year term and transferred power in democratic elections in a country that has experienced three coups and constant political instability since it was established in 1947.

The election is being watched closely by the United States, which relies on the nuclear-armed country of 180 million people for help fighting Islamic militants and negotiating an end to the war in neighboring Afghanistan.

The Pakistani Taliban, which has been waging a bloody insurgency against the government for years, tried to disrupt the election because the militants believe the country’s democracy runs counter to Islam. The government responded by deploying an estimated 600,000 security personnel across the country to protect polling sites and voters.

Many Pakistanis seemed determined to cast their ballots despite a series of gun and bomb attacks.

“Yes, there are fears. But what should we do?” said Ali Khan, who was waiting to vote in the northwestern city of Peshawar, where one of the blasts took place. “Either we sit in our house and let the terrorism go on, or we come out of our homes, cast our vote, and bring in a government that can solve this problem of terrorism.”