Image copyright Reuters Image caption Nawaz Sharif has survived one court ruling but now faces a fresh investigation

The leak of 11 million documents held by the Panama-based law firm Mossack Fonseca identified links between many political and business leaders around the world and offshore companies and accounts. Among them was the Pakistani prime minister's family.

The Pakistani Supreme Court has now ordered an investigation into their affairs by a joint team of civil and military investigation agencies, as the BBC's M Ilyas Khan explains.

What did the Panama Papers reveal?

The leaks in April 2016 revealed that three of Pakistani Prime Minister Nawaz Sharif's children owned offshore companies and assets not shown on his family's wealth statement.

The companies identified so far include three British Virgin Islands-based companies Nescoll Ltd, Nielsen Enterprises Ltd and Hangon Property Holdings Ltd, incorporated in 1993, 1994 and 2007 respectively.

These companies have been used to channel funds to acquire foreign assets, including some apartments along Park Lane in London's Mayfair area.

The insinuation that the companies were meant to hide or launder ill-gotten wealth or to avoid taxes called his credentials into question.

Image copyright AFP Image caption The Panama revelations led to protests around the world - and, here in Iceland, the resignation of the prime minister

What does Mr Sharif say?

Mr Sharif and his family have denied wrongdoing. In November, they told the Supreme Court that their London property was bought through investments in companies owned by the Qatari ruling family.

The prime minister has called the leaks the work of people "targeting me and my family for their political aims". In an address to the nation on 5 April 2016, he said those "who use ill-gotten wealth don't keep assets in their own names".

Initially, however, the leaks appeared to trigger panic in the top circles of the ruling PML-N party. The pressure was believed to be the reason behind Mr Sharif's unscheduled departure for London on 13 April 2016 to keep a rare appointment with his doctors.

This week, the sudden emergence of billboards supporting the prime minister and his government in parts of Punjab and Sindh provinces was seen by many as an attempt to whip up public support in case of an adverse ruling by the Supreme Court.

The prime minister has not yet commented on the Supreme Court's decision, but his top aides have called it a victory for the ruling party, which had proposed a judiciary-led investigation at the start.

Image copyright Reuters Image caption Supporters of Nawaz Sharif welcomed the court's decision not to remove him from office

How did the Supreme Court ruling come about?

The ruling came at the end of a year-long process in which the court examined thousands of pages of evidence and heard lengthy arguments by lawyers from both sides.

The Panama Papers leaks came at a time when Mr Sharif's government was still recovering from the 2014 siege of Islamabad by opposition politician Imran Khan which kept the federal capital paralysed for four months.

Back then it was believed that some elements in the security establishment were backing the protests to prevent Mr Sharif from taking domestic and foreign policy initiatives independently of the military.

With the Panama leaks hitting the headlines, the government again come under pressure from Mr Khan and smaller groups who demanded his resignation and threatened another lockdown of Islamabad.

They filed petitions at the Supreme Court for the prime minister to be disqualified.

After initially rejecting the petitions on the grounds that they were based more on hearsay than facts, the Supreme Court constituted a five-member bench in October 2016 to start hearings in the case.

Image copyright AP Image caption Opposition politician Imran Khan wants Mr Sharif to resign

What did the Supreme Court say and what happens next?

In its ruling the court stopped short of removing Mr Sharif from public office. Instead, it has ordered investigators drawn from civilian investigation agencies and military intelligence services to examine the money trail, look at records where available and obtain testimony from key players.

The team - in front of whom the prime minister and his children have been ordered to appear - will submit its report to the court in two months' time.

Critics believe two months is too short for the team to conduct an investigation that takes in Pakistan, the UAE, Qatar and the UK, not to mention Panama. They also point out that two judges out of five, including the chief justice of Pakistan, suggested that the prime minister be disqualified.

Many opposition leaders, including former President Asif Zardari and Imran Khan, have suggested the prime minister should resign as a fair investigation is not possible if he remains in power.

Has the episode weakened Mr Sharif?

Speculation that a ruling in the case could put Mr Sharif in immediate trouble and bring forward elections due in 2018 has eased for now.

But the verdict has not eased the air of acrimony that has marred Pakistani politics since 2014.

The fact that the court has not cleared the prime minister's name and has directed him to appear before investigators will be used by the opposition to chip away at his legitimacy and personal integrity.

Allegations of corruption have chased Mr Sharif since the 1980s. And much of what the Panama Papers have revealed now was the subject of a federal inquiry in the mid-1990s.

Mr Sharif ordered that inquiry closed when he came into power in 1997, calling it "politically motivated". But this time he and his family have had to acknowledge they used offshore companies to acquire foreign assets.

The petitioners, meanwhile, led by Mr Khan, have not fared much better. They will continue to be taunted by the prime minister's camp that they entertained politically motivated charges that they could not prove in court.

As of now, the air of acrimony is likely to continue and even worsen when the investigators begin their work. And all this is happening at a time when the government has lost much of its territory to the military and elections are approaching.