Finding that a Yemeni cleric and his assistant had been deprived of a fair trial because of errors by the presiding judge, a federal appeals panel in New York on Thursday overturned their convictions in a prominent terrorism case once hailed by the Bush administration as a significant blow to Al Qaeda.

The appeals court judges found that the defendants, Sheik Mohammed Ali Hassan al-Moayad and his aide, Mohammed Mohsen Yahya Zayed, did not receive a fair trial because the trial judge, Sterling Johnson Jr., allowed the jury to hear inflammatory testimony and other evidence that prejudiced the defendants’ case.

The appeals panel sent the case back to the lower court, Federal District Court in Brooklyn, but in a highly unusual step, directed that it be assigned to a different judge.

Judge Johnson presided over the five-week trial in 2005. Both defendants were convicted of charges including conspiracy to support Al Qaeda and Hamas, and were sentenced to long prison terms.

Even before the trial, the case received wide attention when the government’s chief witness, a Yemeni informer, set himself on fire outside the White House. And in 2003, when John Ashcroft, then the attorney general, announced the charges against Sheik Moayad, he said the sheik had admitted to having given Osama bin Laden $20 million before the Sept. 11 terror attacks.

But in overturning the verdict, the three-judge panel of the United States Court of Appeals for the Second Circuit, in Manhattan, ruled that Judge Johnson erred in allowing the jury to hear evidence like the graphic testimony of a survivor of a fatal 2002 bus bombing in Tel Aviv, in which the defendants had not been implicated. Prosecutors had said the testimony was necessary to establish that the defendants knew that Hamas, which claimed responsibility for the bombing, engaged in terrorist activity, a point the defendants did not dispute.

Judge Barrington D. Parker Jr., writing for the appellate panel, said that the bombing, which killed six people, “was almost entirely unrelated” to the charges.

He also wrote that Judge Johnson should not have allowed testimony from another witness, Yahya Goba, who described spending time at a Qaeda training camp in Afghanistan that Mr. bin Laden visited.