Pakistan's Supreme Court has ruled there is insufficient evidence to order Prime Minister Nawaz Sharif's removal from office over corruption allegations levelled by the opposition and it ordered further investigations.
A verdict to dismiss Sharif would have left his party in power but would have sparked turmoil at a time when Pakistan is experiencing modest growth and improved security, and the civilian government and powerful military have appeared to come to uneasy terms.
Two of five judges on the court bench recommended that Sharif should step down but they were out voted.
The court ordered a joint investigation team to be formed to look into allegations around three of Sharif's four children using offshore companies to buy properties in London.
Analysts and opposition politicians said the ruling was a blow to Sharif's credibility and the inquiry's findings could yet weaken the prime minister as he heads into a general election, due by May 2018.
But for now, Sharif and his ruling Pakistan Muslim League-Nawaz, are celebrating.
Sharif's daughter and his presumptive political heir, Maryam Nawaz Sharif, posted a photo on her Twitter account of the family welcoming the court's decision.
"We are ready for all kinds of investigation," Sharif's defence minister, Khawaja Asif, told reporters outside the court.
The Supreme Court agreed last year to investigate the Sharif family's offshore wealth after opposition leader Imran Khan threatened street protests following the leaking of the "Panama Papers" in 2015.
Khan called on Sharif to step down until the investigation was completed.
Documents leaked from the Panama-based Mossack Fonseca law firm appeared to show that Sharif's daughter and two sons owned offshore holding companies registered in the British Virgin Islands and used them to buy properties in London.
The opposition accuses Sharif of failing to explain the source of offshore money and of lying to parliament.
Sharif, one of Pakistan's richest men, told parliament last year that his family wealth was acquired legally in the decades before he entered politics.
The president of the Supreme Court Bar Association said the ruling showed that none of the judges had accepted the truthfulness of Sharif's speech to parliament.
Farogh Naseem, a Supreme Court lawyer and sitting senator, said Sharif could breathe easy, for now.
"It was a close call for the prime minister ... for the time being he has been saved from being disqualified," he told Reuters.