ISLAMABAD, Pakistan — A Pakistani court ruled Monday that former Prime Minister Nawaz Sharif was not eligible to run in upcoming parliamentary by-elections because he had been convicted of a crime.

The decision was a major political setback for Sharif, making it impossible for the bitter opponent of U.S.-backed President Pervez Musharraf to become prime minister unless the ban on his candidacy is overturned. Sharif, a deeply populist politician, leads the junior party in the governing coalition.

Sharif had been barred from running in February elections because of convictions related to his ouster in a 1999 coup. Earlier this month the nation's election commission effectively cleared him to run in by-elections scheduled for Thursday after a tribunal set up to decided the matter failed to reach a consensus.

However, a candidate and a voter from the Lahore constituency Sharif had planned to contest subsequently petitioned the High Court to bar his candidacy.

On Monday, a three member bench of the court disqualified him because of his conviction, according to the court.

Sharif's party said it would consult with its lawyers to decide how to proceed.

"We reject this decision. This is a conspiracy," Sadiqul Farooq, a spokesman for Sharif's party, told Geo TV.

Ashtar Ausaf, Sharif's lawyer, told Dawn News TV he was "appalled" by the verdict. He complained that the court handled the case in a "slipshod" manner and disposed of it in just three hours.

Following the court ruling, dozens of Sharif's supporters, including several lawyers, chanted "Go Musharraf go" and "Musharraf is dog" outside the court, TV footage showed. Angry lawmakers walked out of the provincial assembly in protest, Geo TV reported.

Musharraf ousted Sharif in a 1999 military coup, forcing him into exile for eight years. Sharif returned in November to lead his party into the elections.

Since then, Sharif has repeatedly demanded Musharraf's impeachment, accusing the former army chief of running the country as a dictatorship.

Though his party finished second in February elections — behind the party of the slain leader Benazir Bhutto — a recent poll showed him to be far and away the most admired politician in the country and indicated his party had become Pakistan's most popular.

The court referred a decision on Sharif's brother, Shahbaz, back to the election commission, effectively allowing him retain his job as chief minister of the Punjab province.

Shahbaz Sharif was elected in a by-election to the provincial assembly following his acquittal in a murder case in March after the families of the dead suddenly withdrew their accusations.

The court decision came amid a rift between Sharif's Pakistan Muslim League-N and the dominant party in the coalition, the Pakistan People's Party, which is led by Bhutto's widower Asif Ali Zardari.

Sharif pulled his members from the Cabinet over a dispute over how to reinstate dozens of senior judges Musharraf fired last year. Sharif, whose party is participating in recent street protests led by lawyers, has demanded the government immediately restore the judges to the bench.

Zardari has sought to link the return of the judges to constitutional reforms that could take months to pass.

Sharif and Zardari met several times to discuss the rift, but have yet to resolve the disagreement.

Sharif's insistence that the Supreme Court is illegitimate without the fired judges could make it politically difficult for him to appeal Monday's decision.

Associated Press reporters Sadaqat Jan and Zarar Khan contributed to this report.