In the summer of 2005, the federal government announced that it had uncovered terrorists in the sleepy town of Lodi, California. Soon began one of the first big terrorism trials of the post-9/11 era, resulting in the conviction of Hamid Hayat, a 23-year-old American with a sixth-grade education accused of attending a terror training camp in Pakistan. The Hayat case pioneered a controversial strategy of “anticipatory prosecution” that has become a hallmark of terrorism cases—targeting individuals whom the government suspects present a potential risk of violence and incarcerating them long before they commit any such act.

Earlier this month, a federal judge recommended vacating Hayat’s conviction because she concluded he did not receive a fair trial. The decision offers the promise of long-delayed justice for a man who is likely innocent. But it also underscores how easy it is to exploit national security fears amid popular prejudice. The toxic stew of circumstances that led to Hayat’s conviction—a paid government informant, an overzealous prosecution seeking a high-profile conviction, and jurors caught in their own prejudice—still afflicts Muslim Americans in terrorism cases today.

As a civil rights lawyer at the time, I witnessed firsthand how aggressively the FBI investigated the local Muslim community. After accusing Hayat of attending a training camp, the government suggested that a larger terrorist cell operated in Lodi. One evening shortly after Hayat’s arrest, several attorneys and I held a legal education session at a mosque packed with terrified community members. These Pakistani Americans described how FBI agents tailed them for days, interrogated them at work, and even followed their sons to the ice cream parlor. As we advised people of their rights, FBI vehicles circled the mosque late into the night in what appeared to be an overt show of intimidation. Although the investigation uncovered no cell or plots of violence, it shattered the local Muslim community’s sense of security and belonging.

In 2006, a jury convicted Hayat of furnishing material support to terrorism and making false statements to the FBI, and the trial judge sentenced him to 24 years in federal prison. But from the beginning, much about the case stank.

Faced with this paltry evidence, the jury deliberated for nine days and initially deadlocked before finding Hayat guilty

The evidence that Hayat had attended a training camp was woefully thin. First, Hayat had “confessed,” after hours of interrogation, in a videotaped statement that strained credulity. A former FBI agent and 35-year bureau veteran called it the “sorriest confession” he had ever viewed. Second, the government presented a recording in which, after much goading, Hayat promised an informant—who was paid $230,000 over three years by the government—that he would attend terrorist training when he got to Pakistan. The informant, however, had no evidence that Hayat had actually done so, and the government conceded that the informant had earlier made implausible claims about the presence of high-level al-Qaida officials in Lodi. Finally, prosecutors argued that a not uncommon Arabic prayer found in Hayat’s wallet would only be carried by someone who saw himself as a “jihadi warrior.”

Faced with this paltry evidence, the jury deliberated for nine days and initially deadlocked before finding Hayat guilty. The jury foreman later told a journalist that he couldn’t let Hayat go free “on the basis of what we know of how people of his background have acted in the past”—the very definition of prejudice. Ultimately, inflammatory testimony and fear of Muslims seemed to seal Hayat’s fate.

Until now. Magistrate Judge Deborah Barnes recommended on Jan. 11 that Hayat receive another shot at justice. She ruled that Hayat’s lawyer, a novice who had never previously handled a criminal case, provided him constitutionally inadequate representation. For instance, Barnes found that multiple witnesses could have testified that Hayat was continuously in his family’s village at the time the government accused him of attending a training camp and that the Arabic prayer is a common Islamic supplication. With an adequate defense, the jury might have acquitted Hayat. The case will now return to the district court judge to decide whether to accept the ruling. Depending on what happens next, the decision can then be appealed to the 9th U.S. Circuit Court of Appeals by either side.

While Barnes’ decision focused on an ineffective defense, it also demonstrates how overzealous prosecutions can lead to convictions above justice in terrorism cases. Hayat’s case shows precisely what is wrong with many “anticipatory” terrorism cases.

With paid informants who are largely unaccountable to anyone aside from their government handlers, unfamiliar Islamic references likely to prejudice a jury, overbroad charges of material support to terrorism, and a climate of fear, the risk of unfair terrorism trials is perpetual.

The government and the higher courts now have an opportunity to do the right thing: to accept the magistrate’s findings and allow Hayat to go free. This case serves as a powerful reminder to all Americans that the invocation of national security can too easily license a miscarriage of justice.