Pakistan's Supreme Court has ruled there is insufficient evidence to force Prime Minister Nawaz Sharif's removal from office over corruption allegations levelled by the opposition, but has ordered further investigations.
A verdict to dismiss Mr Sharif would have left his party in power but would have brought 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 Mr Sharif should step down, saying he was dishonest "to the nation as well as to the Parliament", but they were outvoted.
Presenting its 549-page judgment amid tight security in the capital Islamabad, the court ordered a joint investigation team be formed to look into allegations around three of Mr Sharif's four children using offshore companies to buy properties in London.
The team has two months to complete its inquiry, after which a special bench will decide what action to take, the court said in a ruling that opens with the epigraph from Mario Puzo's novel The Godfather: "Behind every great fortune there is a crime".
Pakistan's stock market jumped after the court's decision with the benchmark index closing up 2.39 per cent. Mr Sharif is seen as pro-business.
Analysts and opposition politicians said the ruling was a blow to Mr 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, Mr Sharif and his ruling Pakistan Muslim League-Nawaz, are celebrating.
Mr Sharif's daughter and his presumptive political heir, Maryam Nawaz Sharif, posted a photo on Twitter of the family welcoming the court's decision.
"We are ready for all kinds of investigation," 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 protests after the leaking of the Panama Papers.
"The Prime Minister should immediately resign at least for the 60 days until JIT completes its work," Mr Khan told reporters, referring to the joint investigation team.
The opposition accuses Mr Sharif of failing to explain the source of offshore money and of lying to Parliament.
Mr 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 Mr Sharif's speech to Parliament.
Farogh Naseem, a Supreme Court lawyer and sitting senator, said Mr Sharif could breathe easy, for now.
"There is no clean chit for the Prime Minister, but for the time being he has been saved from being disqualified."