Nawaz Sharif, a wealthy businessman who twice served as Pakistan’s prime minister in the 1990s and brought the country into the world’s nuclear club, appeared Saturday night to be headed to an unprecedented third term in the post.

He declared victory to supporters in Lahore, where his Pakistan Muslim League-N has long dominated politics, after partial and unofficial results in a landmark national election showed his ­center-right party had locked in enough seats in the National Assembly to lead a coalition government.

“Results are still coming, but there is a confirmation that PML-N will emerge as the largest party,” Sharif said. “We should thank Allah that he has given PML-N another chance to serve you and Pakistan.”

Sharif, 63, who was toppled in a coup in 1999, had been widely favored to emerge as premier, but no party appeared to have won enough votes to claim a simple majority of the 272 directly elected National Assembly seats. Analysts projected that PML-N would win at least 100 seats.

Brokering a coalition government could take weeks. In his speech, Sharif also voiced confidence that results would show by Sunday that he would have enough seats to claim the required majority. But if that doesn’t happen, he will have to turn to smaller independent parties — or seek the support of his strongest rivals, the cricketer-turned-politician Imran Khan and the Pakistan People’s Party (PPP), which just ended a five-year term.

Khan’s third-party Movement for Justice and the PPP appeared in early results likely to win the same number of seats, about 35.

“If the numbers shaping up come true, this is a stunning victory for PML-N,” Cyril Almeida, a columnist for the Dawn newspaper, said on Twitter.

Khan’s campaign manager, Asad Umar, said the PML-N had triumphed. “They have emerged as the largest party,” Umar told Geo TV, Pakistan’s largest cable news channel. “I want to congratulate the party.”

The Afghan presidential palace said that they hoped that “the government that will be formed as a result of the election will create a brotherly and peaceful atmosphere with Afghanistan.” The palace said it was fully prepared to cooperate with Pakistan in the annihilation of terrorism “so that the Afghan and Pakistan fellow-brother nations can be saved from this calamity” and bring stability to the region.

Millions of exuberant Pakistanis, many voting for the first time, turned out in higher-than-expected numbers Saturday in defiance of insurgent violence aimed at sabotaging the balloting that will bring a historic transfer of power between elected governments.

Scattered gun and bomb attacks marred an otherwise celebratory day in a nation mired in economic crisis and locked in a fight with a virulent native Taliban insurgency. By the time polls closed, at least 20 people had died in attacks, the most serious targeting a pro-U.S. political party in the southern port city of Karachi.

The election commission projected that more than 60 percent of the nation’s 86 million voters cast ballots for national and provincial assemblies — a number that, if confirmed, would represent the highest turnout since 1970, when the populist PPP swept to power.

A religious conservative sometimes criticized as soft on militancy, Sharif is also a realist. His advisers say he is likely to seek friendly ties with Washington, which for decades has been Pakistan’s principal financial patron. He has talked of extracting Pakistan from the U.S. war against extremists, including those being sheltered on Pakistani soil, but provided no plan for doing so.

His campaign touted his experience as a businessman, asserting that he could tackle systemic economic problems, notably an energy crisis that has crippled important industries. He also promised low-interest loans to new graduates, in an effort to siphon support away from Khan, who has built up a sizable youth base.

Sharif cited the nation’s nuclear tests in 1998 as an example of his strong leadership. Pakistan needed nuclear weapons, he said, to counter India’s and to pressure that nation into detente with Pakistan, its historical enemy.

In many areas, particularly vote-rich Punjab province, the race for prime minister had narrowed to a battle between Sharif and Khan, whose youth movement made him an unpredictable factor in a cliffhanger election.

Half of those registered were first-time voters between 18 and 39, election officials said, and many had been galvanized by Khan, who has campaigned relentlessly for more than two years against the major parties: Sharif’s PML-N and the PPP.

Khan remains hospitalized with back injuries after a fall from a forklift this week during a campaign rally in Lahore. His campaign said he should be recovered in two or three weeks. He would be a force to be reckoned with in any potential coalition government — likely to be a fractious one at a time when the United States and its NATO partners are hoping for stability in the nuclear-armed nation.

Khan and Sharif both benefited from not being targeted by the Pakistani Taliban, which instead targeted the secular parties: the PPP, the anti-militant Awami National Party (ANP) and the progressive Muttahida Qaumi Movement. On Saturday, a Taliban-
ordered blast struck an ANP party office in Karachi, killing at least 10 people, according to the Associated Press, and a roadside bomb hit a bus full of party supporters, killing one of them.

Haq Nawaz Khan in Peshawar contributed to this report.