By Lipika Pelham and Caroline Davies, BBC
Pakistan's second and third political blocs have agreed to co-operate after elections in which jailed ex-PM Imran Khan's supporters came first.
Ex-PM Nawaz Sharif's PMLN and Bilawal Bhutto Zardari's PPP issued a statement saying they planned to work together to bring political stability.
If they do form a government, the move is likely to anger Khan's followers.
His PTI party was barred from taking part in the election, so most of its candidates stood as independents.
Earlier, police used tear gas to disperse a crowd of Khan's supporters in Rawalpindi.
According to final results, independents won 101 of the National Assembly seats. BBC analysis shows 93 of them went to PTI-backed candidates.
That puts them ahead of the PMLN, who won 75, and the PPP, who gained 54.
The two parties formed an alliance to oust Mr Khan from power in 2022 and ruled until last August.
The Karachi-based MQM party has also made a surprising return in the polls, winning 17 seats, and could play a role in any coalition.
As wrangling continues, independent candidates who did not win have flooded courts with vote-rigging allegations.
Both the PTI, which was blocked from taking part in the election, and Sharif's PMLN say they want to form the next government.
The result was a surprise as most observers had expected Sharif's party - widely seen as having the powerful military's backing - to win, given Khan had been jailed on charges ranging from corruption to having married illegally and his party was barred from the ballot sheet.
To govern, a candidate has to show they are at the head of a coalition with a simple majority of 169 seats in the National Assembly.
Of the National Assembly's 366 seats, 266 are decided by direct voting and 70 are reserved - 60 for women and 10 for non-Muslims - and these are allocated according to the strength of each party in the assembly.
Under Pakistan's rules, independent candidates are not eligible to be allocated reserved seats in parliament.
The PTI, among several other parties, has called for protests against the results, alleging they have been rigged.
On Sunday, police blocked streets near the electoral commission building in Rawalpindi with barbed wire and large trucks, preventing any protesters from accessing it.
For about 90 minutes, a crowd of a few hundred protestors chanted on the street. Then the atmosphere turned. Police used several rounds of tear gas to disperse the crowd, which then left the area.
The Punjab police told the BBC that there was a section 144 in place - a colonial-era law that stopped a gathering of more than four people.
This restriction had been put in place before the election until 12 February, but it detailed that civilians were not allowed to carry firearms, not that they were prevented from gathering.
The PTI's chairman had called for peaceful protests outside electoral commission offices where they were concerned about "forged" results.
Pakistani media reported that the PTI party claimed that the results of at least 18 National Assembly seats were "falsely changed" by election officers.
On Saturday, Sharif - who is thought to be favoured by the military - called for other parties to help him form a unity government.
As negotiations got under way between Khan's political rivals, experts have warned Pakistan could be facing a "prolonged period of political instability".
Dr Farzana Shaikh from the Chatham House think tank told the BBC that the Khan-linked independents were unlikely to be allowed to form a government and many people feared a "weak and unstable coalition" would result from any tie-up between Sharif and the PPP.
Meanwhile, at least six PTI-backed candidates who did not win their seats have lodged legal challenges in the courts to try to get the outcome overturned.
Among them is Yasmin Rashid, who stood against Sharif in Lahore. The petitioners allege collusion in the alteration of election results on specific forms.
Pakistani officials have denied any irregularities. The PMLN has also reportedly formed a legal team to address rigging allegations.
This story was first published by the BBC.