Nawaz Sharif, leader of the Pakistan Muslim League - Nawaz (PML-N) political party, casts his vote for the general election at a polling station in ...

Former Pakistani prime minister Yousuf Raza Gilani casts his vote at a polling station in Multan. (AFP Photo)

Supporters of Pakistan Tehreek-e-Insaf (PTI) enjoy on a street during the General Elections in Rawalpindi. (AFP Photo)

A Pakistani election official empties a ballot box at the end of polling in Islamabad. Polling stations closed at 6:00pm (1300 GMT) in Pakistan's historic ...

Pakistani Hazara Shiite community members cast their votes at a polling station in Quetta. AFP photo

Residents gather at the site of a bomb explosion in Karachi. AFP photo

Pakistani residents wanting to vote check voter registration lists near a polling station in the village of Dial on the outskirts of Lahore. AFP photo

Toppled in a 1999 coup, jailed and exiled, Nawaz Sharif has made a triumphant election comeback and on Sunday was heading for a third term as Pakistan's prime minister.

The polls were a landmark, marking the first time one elected government was to replace another in a country vulnerable to military takeovers.

But Saturday's vote failed to realise the hopes of many that dynastic politics would end after years of misrule and corruption in the strategic US ally.

Sharif, 63, a wealthy steel magnate from the pivotal Punjab province, held off a challenge from former cricket star Imran Khan who had hoped to break decades of dominance by Sharif's Pakistan Muslim League (PML-N) and the Pakistan People's Party (PPP), led by the Bhutto family.

Khan's Tehrik-i-Insaf (PTI) put up a strong fight and he is likely to remain a force in politics.

"Nawaz's victory says two things about Pakistan: one, the people of Pakistan prefer the comfort of status quo over the uncertainty of revolutions; and two, all roads to the centre go through Punjab, and in Punjab, people are right-leaning and conservative," said senior journalist Nusrat Javeed.

"Still, for a party that only really arrived on the political scene in a serious way two years ago, PTI's performance was remarkable, to say the least."Sharif declared victory in a jubilant speech to supporters.

On Sunday, television channels said results so far showed that the PML-N had captured 94 seats of the 272 National Assembly seats that were contested.

Based on trends, it was likely to get around 130, and should easily be able to make up the required majority of 137 with support from independents and small parties.

The PTI has secured 21 seats while the PPP won 19. The elections, held on Saturday, were marred by a campaign by Islamic fundamentalists to block the voting.

Sharif, a religious conservative, has said the army, which has ruled the country for more than half of its turbulent history, should stay out of politics.

But he will have to work with Pakistan's generals, who set foreign and security policy and manage the nuclear-armed country's difficult relationship with the United States as NATO troops withdraw from neighbouring Afghanistan in 2014. Sharif also believes Pakistan should reconsider its support for the U.S. war on Islamist militancy, which has earned the country billions of dollars in aid.

Despite pre-poll violence and attacks on Saturday that killed at least 17 people, millions turned out to vote.

File photo of Nawaz Sharif. (Reuters)

Sharif's party may not have enough seats to rule on its own and may be forced into a coalition, which could make it difficult to push reforms needed to revive the economy.

Sharif, who advocates free-market economics, is likely to pursue privatisation and deregulation to revive flagging growth.

He has said Pakistan should stand on its own two feet but may need to seek a another bailout from the International Monetary Fund to avoid a balance of payments crisis.

Sharif will have to ease widespread discontent over endemic corruption, chronic power cuts and crumbling infrastructure. He has described Pakistan as a "mess".

Cricketing hero Khan in the end did not have the momentum needed to trip up Sharif despite his popularity among urban youths, many of whom were voting for the first time in an election that saw a robust turnout of 60 percent.

They had rallied behind Khan's calls for an end to graft and a halt to US drone strikes against suspected militants on Pakistani soil, widely seen as a violation of sovereignty.

Imran Khan's party concedes defeat

The party of Pakistani cricket star Imran Khan early Sunday conceded defeat in general elections, but said it would form the next government in the terror-hit northwestern province of Khyber Pakhtunkhwa.

Assad Omar, a senior leader in Pakistan Tehreek-e-Insaf (PTI), sent his congratulations to the centre-right Pakistan Muslim League-N, which he said had emerged as the largest party, as results started to come through.

File photo of Imran Khan. (AFP Photo)

But speaking to private TV channel Geo, he refused to be defeatist.

"For Tehreek-e-Insaf it is a big day, a golden day. A party which has no existence in parliament has emerged the second largest national party and the leading party in Khyber Pakhtunkhwa where God willing it is going to form a government," he said.

Northwestern Pakistan is on the frontline of a nearly seven-year domestic Taliban insurgency and suffers near daily bomb and shooting attacks blamed on militants.

Khan has called for an end to military operations and peace talks with the Taliban, making his party's win in the northwest an interesting proposition.Omar said the PTI leader, who is flat on his back in hospital with a fractured spine after falling from the stage of a campaign rally, was following the results.

"He will give his reaction tomorrow, but I will say he knows how to win and how to lose, and after losing, how to come back. He is taking these results like a sportsman," Omar said.

Millions of Pakistanis on Saturday voted for the 342-member national assembly and four provincial assemblies in Khyber Pakhtunkhwa, Punjab, Sindh and Baluchistan.

"It is very clear that PTI has emerged as the largest party in Khyber Pakhtunkhwa, so we will form our government here with the help of like-minded political parties," said Shaukat Yousafzai, who won a seat for the party in the provincial assembly.

A Pakistani voter crosses a bridge as he arrives to cast his vote while other stands in a queue outside a polling station in Islamabad. Pakistani voters went to the polls, braving Taliban threats to cast their ballots in an election marking a historic democratic transition for the nuclear-armed state. AFP

"We will make a coalition with all those political parties and MPs who were never involved in corruption," he added.

PPP suffers huge setback

In an embarrassing setback to Pakistan Peoples Party that ruled the country since 2008, former Pakistan Prime Minister Raja Pervez Ashraf lost the election along with his predecessor Yusuf Raza Gilani's two sons.

Ikhlas drew 82,339 while Raja Pervez Ashraf was way down with 23,233 votes received.

Similarly, Gilani's both sons, Ali Musa Gilani and Abdul Qadir Gilani, have lost in polls from their Multan constituencies.

Abdul was kidnapped by suspected Taliban terrorists last week while he was campaigning.

Earlier, a Pakistani court had disqualified Yousuf Raza Gilani.

Going by the unofficial results, the PPP ? which ruled the country for the last five years ? has faced a major setback and has been effectively confined to Sindh.

As per available trends, PPP is likely to come a distant third but could play an important role in the government formation if PML-N fails to get a simple majority in the 342 seat strong National Assembly.

Top leaders of the party, including former Information Minister Qamar Zaman Kaira, lost their seats in the largest province of the country, Punjab.

Currently, the PPP has a majority in the upper house of Parliament, at least for the next one and a half years. Major legislation would not be possible for the new ruling party without the PPP's consent.

Pakistani voters queue for their turn to cast their vote outside a polling station in Karachi. Pakistani voters went to the polls, braving Taliban threats to cast their ballots in an election marking a historic democratic transition for the nuclear-armed state. AFP

In the 1970 elections, Zulfikar Ali Bhutto's PPP conquered Punjab, with Lahore being considered one of the party's hubs for some time after that stunning victory.

But the unofficial results of the 2013 election show that the party has once again been confined to Sindh, as it was in 1997 when the Benazir Bhutto-led PPP secured less than 20 National Assembly seats, Express News reported.

The party tried hard to restore its image in Punjab during the last five years but apparently its poor performance shattered its dreams. The PPP also promised to bifurcate Punjab, but even this slogan could not earn it votes in south Punjab, it said.

In the 2008 elections, the Asif Ali Zardari-led PPP secured 97 National Assembly seats. After getting 24 reserved seats for women and four reserved seats of minorities, the total number of NA seats for the PPP was 124 in a house of 340. The party formed a coalition government with the help of MQM, ANP and JUI-F.

Bloody Election Day

A string of bomb blasts marred election day, with one attack on a party office in the southern city of Karachi killing 11 people and wounding about 40.Pakistan's Taliban, who are close to al Qaeda, have killed more than 125 people in election-related violence since April.

Pakistani women leave after casting their votes as people wait in a queue outside a polling station in Islamabad. AFP

The group, which is fighting to topple the government, regards the poll as un-Islamic.

Despite Pakistan's history of coups, the army stayed out of politics during the five years of the last government and threw its support behind Saturday's election.

However, some fear the military could step back in if there were a repeat of the incompetence and corruption that frustrated many Pakistanis during the last government.

Sharif, who was toppled in a 1999 bloodless coup by former army chief Pervez Musharraf, may take steps to improve ties with Pakistan's arch-enemy, India. Efforts to boost trade between the neighbours have stalled due to suspicion on both sides.

An European Election Observation Mission official monitors polling as female voters wait for their turn to cast their vote at a polling station in Islamabad. AFP

If Sharif is forced into a coalition, he may look to Islamist parties to cobble together a majority in parliament.

On top of the 272 contested seats, a further 70 - most reserved for women and members of non-Muslim minorities - are allocated to parties on the basis of their performance in the constituencies. To have a majority of the total of 342, the government would need 172 seats.