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 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 contest 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 maneuvering will be watched closely by Pakistan's neighbors as well as regional powers such as China, Russia and the US.
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 US-led conflict in neighboring 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 US 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 US-designated terrorist Hafiz Saeed, who has a $10 million US bounty on his head.The candidates campaigned under the little known Allah-o-Akbar Tehreek party because Lashkar-e-Taiba is banned.
Imran Khan: Where he stands
On military dominance
Pakistan's powerful military establishment has directly or indirectly ruled the country for most of its seven decades of existence. Khan dismissed widespread allegations of manipulation during the election campaign by the military and sidestepped discussion on its role in civilian affairs, by simply saying the army is Pakistan.
On the treatment of women
Khan has publicly expressed his admiration for the justice dispensed against women by "jirgas" - or councils of elders. These councils have banned women from voting; given children to old men to marry in order to settle disputes; and ordered a woman to be stripped naked and paraded through a village for a dishonour or crime committed by a male relative. Khan also has attacked Pakistan's political liberals and berated Western feminist ideals, saying it degrades motherhood.
On the blasphemy law
Khan campaigned openly promising to support and defend Pakistan's blasphemy laws. Rights groups and minorities say the measures are often used to settle local scores. The laws, which carry an automatic death sentence, sometimes have incited mobs against entire neighbourhoods at the merest suggestion that blasphemy has been committed.
On US relationship
Khan has been critical of the United States-led invasion of neighbouring Afghanistan and drone strikes that have killed militants - and sometimes civilians - on the Pakistani side of the border. He says former Pakistani leaders have sold out the country's pride for billions of dollars in US aid. He says he wants good ties with Washington but on an equal footing, calling the current relationship one-sided.
On the Taliban
Khan denies allegations by the US and Afghanistan that Pakistan assists or harbours Taliban militants, and his statements on the issue mirror the flat-out denials by the army.
On Islamic militancy
Khan has been a strong proponent of talks with Pakistan's Taliban and has said the emergence of the group in the border areas is a reaction to the US intervention in Afghanistan. He said that the presence of international troops in Afghanistan has hurt Pakistan and strengthened the militants.
On India
Khan says he wants good relations with neighbouring India but said the core of their differences is the disputed Kashmir region, which is divided between the two nuclear powers and claimed by both. Khan says there is a desperate need for an international reckoning of the widespread human rights violations being committed by Indian troops against Kashmiris. He said the two countries have to end the tit-for-tat accusations.
- AP