It's official: Pakistan's Election Commission on Friday declared former cricket star Imran Khan's party the winner of Pakistan's historic third consecutive election of a civilian government, but he didn't win an outright majority and must form a coalition.

After two days of tediously slow vote counting, Khan's Pakistan Tehreek-e-Insaf party won 114 of 269 seats in the National Assembly with his nearest rival, Shahbaz Sharif's Pakistan Muslim League, winning 63 seats. Sharif, who heads the party of jailed ex-prime minister Nawaz Sharif, earlier rejected the results charging widespread fraud and manipulation.

In Pakistan, where a British-modelled parliamentary system is in place, voters on Wednesday elected lawmakers to both its National Assembly and its four provincial Parliaments.

Fawad Chaudhry, the spokesman for Khan's party, said efforts were already underway to form a coalition, looking to both independents and allies, but the process is likely to take several days. Still, on Thursday the 65-year-old Khan made his first speech to the nation declaring his party victorious based on projections.

"Today in front of you, in front of the people of Pakistan, I pledge I will run Pakistan in such a way as it has never before been run," Khan said, vowing to wipe out corruption, strengthen institutions he called dysfunctional and regain national pride by developing international relationships based on respect and equality.

But there is a long way to go before Pakistan's national and provincial governments are in place and Khan can set out on his agenda.

His opponents and rights groups charge that widespread fraud and massive manipulation gave Khan's party its victory. They allege involvement of Pakistan's powerful military and its intelligence agency known by the acronym ISI. Khan has dismissed the allegations saying polling was the most transparent in the country's 71-year history, which has been dominated by military interference, either directly or indirectly.

Third place in the National Assembly went to the left-of-centre Pakistan People's party with 39 seats. Results from 20 seats were still being counted Friday but they will not change the outcome. Pakistan's National Assembly has 342 seats but only 272 are directly elected by voters. In Wednesday's election, three seats were uncontested because one candidate died, another was disqualified and a third was declared. The remainder of the parliament goes to seats reserved for women and minorities.

A mix of smaller parties and independent candidates whom Khan will have to woo to form a coalition won the remainder of seats in Pakistan's National Assembly. The Election Commission said vote counting was also still underway in 20 remote areas of the country, offering the long-time politician a possibility of more seats but not an outright majority.

Adding confusion to chaos, Sharif, who has rejected the election results won the majority of seats in Pakistan's most powerful Punjab province. His party won 127 of the 297-seat provincial parliament, while Khan's PTI took 117 seats, giving neither an outright majority and forcing both to try to form a coalition government. The Punjab parliament is significant because Punjab is Pakistan's largest province, with 60 percent of the country's 200 million people. If Khan wants to implement his sweeping reform agenda his party needs to control the Punjab Parliament.

Khan's party won a sweeping majority in the conservative Khyber Pukhtunkhwa province, while the Pakistan People's Party, led by Bilawal Bhutto, the son of slain ex-prime minister Benazir Bhutto, won the most seats in southern Sindh's provincial legislature. Pakistan's largest city of Karachi and the country's financial hub is the provincial capital of Sindh.

The restive Baluchistan province beset by militant violence was won by a mix of small parties who will have to form a coalition to rule.

There will likely be days of negotiation before the makeup of Pakistan's National Assembly and four provincial parliaments are clear and the manoeuvring will be watched closely by Pakistan's neighbours as well as regional powers such as China, Russia and the U.S.

Khan in his speech on Thursday revealed a clarity of vision for Pakistan's future international relationships.

While he appeared casual and conciliatory, his words were laced with passion. He said the United States treats Pakistan like a mercenary, giving it billions of dollars to fight the war on terrorism in a region beset with militant extremists.

"Unfortunately, so far our relations were one-sided. America thinks that it gives Pakistan money to fight for them. Because of this Pakistan suffered a lot," said Khan, who has been critical of the U.S.-led conflict in neighbouring Afghanistan.

He offered nothing to suggest improvement in Pakistan's already testy relationship with Washington since President Donald Trump's tweets in January accusing Islamabad of taking U.S. aid and returning only lies and deceit.

Seeking good relations with his neighbours, Khan addressed Pakistan's rival, neighbouring India. The two nuclear powers have had a long-running conflict over the disputed region of Kashmir.

"Take one step toward us and we will take two steps toward you," he said in a peace offering while still decrying widespread human rights abuses in Kashmir.

Khan also advocated an open border policy with Afghanistan, even suggesting the two countries embrace a "European Union" type relationship. The plan seems unlikely, with Pakistan's military already building hundreds of border outposts and an accompanying fence along its western frontier with Afghanistan despite often-violent opposition from Kabul.

Although rights groups and minorities expressed worries ahead of the voting about radical religious groups taking part, moderate voices seemed to have prevailed: None of the 265 candidates fielded by the outlawed Lashkar-e-Taiba won a seat. That includes the son of co-founder and U.S.-designated terrorist Hafiz Saeed, who has a $10 million U.S. bounty on his head.

Get the latest local and international news straight to your mobile phone for free: