Watching the courtroom drama was the countryâs powerful military, which has traditionally decided the fate of civilian governments. There had been hushed speculation that the court, in coming to its decision, had the tacit, if not overt, backing of powerful generals.
The charges against Mr. Sharif and three of his children â two sons and a daughter â stemmed from disclosures last year in the Panama Papers, which revealed that the children owned expensive residential property in London through offshore companies.
In their unanimous verdict on Friday, the justices declared that Mr. Sharif was not âhonestâ and that he was therefore âdisqualified to be a member of the Parliament.â They also ordered the opening of criminal investigations against the Sharif family.
Imran Khan, the opposition politician who has been spearheading the campaign against Mr. Sharif since he took power in 2013, stands to gain the most politically from the prime ministerâs removal. Mr. Khan has doggedly and almost obsessively led the charge against Mr. Sharif and rallied a wide swath of the public against him through a mix of street agitation and court petitions.
The Supreme Court had asked the members of the Sharif family to provide a paper trail of the money they used to buy their London apartments. Investigators found that they were âliving beyond their means.â
Despite repeated court exhortations, Mr. Sharifâs family and its lawyers failed to provide satisfactory documentation, the justices said. Several of the documents they produced were declared fake or insufficient.
A representative of the governing party said that although Mr. Sharif was stepping down, the party had âstrong reservationsâ about the ruling and was contemplating âall legal and constitutional meansâ to challenge it.
Mr. Sharif has called the inquiry into his familyâs finances a conspiracy and has asserted that in his three terms as prime minister he had not been tarred by a major corruption scandal.
The ruling, while expected, leaves undecided the long-term fate of the man who has been a dominating force in Pakistani politics for the better part of three decades.
âI did not expect Nawaz Sharif to go scot-free,â said Hasan Askari Rizvi, a prominent political analyst who is based in Lahore.
âIf he has a long-term vision, he will sit back and guide his political party,â Mr. Rizvi added. âHe and his supporters will portray the court verdict as victimization and a grave conspiracy involving international powers.â
Mr. Sharifâs removal from office throws his political succession plans into disarray. His daughter Maryam Nawaz Sharif, who was being groomed as his political heir, was also implicated in the case.
Political insiders say there are several possible contenders to replace Mr. Sharif: Sardar Ayaz Sadiq, the speaker of the national assembly; Shahid Khaqan Abbasi, the minister of petroleum; Khurram Dastgir Khan, the commerce minister; and Khawaja Muhammad Asif, the defense minister.
âWhoever they bring will be a weak prime minister, as Nawaz Sharif would want to have someone who is more or less in line with his thinking,â Mr. Rizvi said.
Mr. Khanâs supporters had laid siege to the Parliament and other government buildings in 2014 after accusing Mr. Sharif of rigging the 2013 general elections. Another attempt to blockade the capital in 2016 was unsuccessful, but it forced the Supreme Court justices to take up the Panama Papers case.
After the Supreme Court reserved judgment on the case on July 21, Mr. Khan on Wednesday urged the court to announce a verdict without delay.
âThe whole country is at a standstill due to the Panama Papers case,â Mr. Khan said. Critics said Mr. Khan was pressuring the courts.
Political analysts say the court verdict hands Mr. Khan an undeniable political and moral victory.
âImran Khan will be strengthened, but it remains to be seen how he capitalizes in Punjab Province, which is critical to winning the general elections,â Mr. Rizvi said. Punjab, the most populous and prosperous of the countryâs four provinces, has remained a stronghold of Mr. Sharif for decades.
Mr. Sharif presided over a period of relative economic stability and was able to complete a few large infrastructure projects while reducing the crippling power outages that have long afflicted Pakistan.
But the stubborn scandal over the London real estate holdings sullied the reputation of his family.
Mr. Sharifâs political party nonetheless hopes that his achievements can bring it another electoral success next year even if Mr. Sharif cannot run for office.
âWe will make a comeback,â Khawaja Saad Rafique, a party leader, said Friday afternoon at news conference flanked by other senior figures. He said that Mr. Sharifâs âcrime was that he stood for civilian supremacy.â
He urged party workers to remain peaceful and said that the party respects the countryâs institutions. âThere will be no chaos,ââ he said. âWe will move forward with wisdom and not emotion.â
During his most recent tenure, Mr. Sharif had an uneven relationship with the military. His overtures of more openness toward India, Pakistanâs longtime foe, backfired as generals spurned his efforts.
More recently, relations with the military took a darker turn after news reports detailed how civilian officials confronted the military over what they called a failure to act against Islamist groups. Mr. Sharif had to fire his information minister and two top aides to placate the army.
Bilawal Bhutto Zardari, the chairman of the Pakistan Peoples Party, said the Panama Papers ruling was âa real test of our system.â
Some predicted a politically volatile time ahead.
âUntil the elections, this will lead to a period of political instability,â Amber Rahim Shamsi, a prominent journalist who hosts a show on Dawn TV, said of the verdict.
âThe Sharif political dynasty has somehow managed to survive Pakistanâs rough and bloody politics for over three and a half decades through wheeling and dealing,â Ms. Shamsi said. âIt is hard to imagine all the family falling like a pack of cards. Nawaz Sharif has a following and could cash in on political martyrdom to stage a comeback.â