NEW YORK (AP) — There’s enough evidence to support a rare state-level terror case against a man charged with plotting to blow up New York synagogues, a judge ruled Monday in declining to throw out the charges.

The ruling puts the case against Ahmed Ferhani on course toward a trial that will likely pit authorities’ picture of a homegrown, lone wolf terrorist against his lawyers’ account of a mentally unstable man entrapped by police. No trial date has been set.

“At the end of the day, we’ll see what the jury says,” one of his lawyers, Elizabeth Fink, said after court Monday.

Ferhani, a 27-year-old Algerian immigrant, and co-defendant Mohamed Mamdouh were arrested in May 2011 after Ferhani bought three handguns, ammunition and an inert grenade from an undercover detective, police said. Mamdouh, a 21-year-old American citizen of Moroccan descent, had been dropped off nearby before the buy and was arrested soon afterward, according to police. Both have pleaded not guilty.

Monday’s ruling involved only Ferhani.

Authorities said the two planned an attack to avenge what they saw as mistreatment of Muslims around the world. Ferhani suggested posing as a Jew so he could infiltrate a synagogue and leave a bomb inside, prosecutors have said in court documents. At a meeting to arrange the gun buy, Ferhani said he needed the weapons “for the cause,” according to a court complaint.

Most terror cases are federal, but Ferhani and Mamdouh were charged under a state law passed shortly after the Sept. 11 attacks.

The case — announced with the gravitas of a City Hall press conference — hit a bump early on, when a grand jury declined to indict the two men on the initial top charge against them, a high-level terror conspiracy count. But they were indicted on other terror and hate crime charges that carry up to 32 years in prison.

Ferhani’s lawyers sought to get those charges dismissed, saying the case was based on insufficient evidence, drew on dubious police tactics and mistakenly invoked a terror law to prosecute what was an alleged street crime.

Manhattan state Supreme Court Justice Michael Obus disagreed.

“The overt acts alleged in support of the conspiracy charges — and again, reflected in the evidence before the grand jury — assert (Ferhani’s) very tangible plans to use the weapons in a religiously-motivated fashion against Jews and other non-Muslims,” Obus wrote in his ruling Monday.

Ferhani’s lawyers say police manipulated a man they knew had psychological problems to turn ambiguous remarks and a staged weapons buy into a trumped-up terror case. Ferhani has been institutionalized for psychiatric problems as many as 30 times — at least five of them after his family called police, his lawyers have said.

“We think this is a case that was brought in bad faith to justify the illegal and unconstitutional campaign of the police and the district attorney’s office to further their agendas … and to criminalize the Muslim community,” Fink said after court.

In court papers, Fink had cited stories by The Associated Press that described efforts to monitor Muslim student groups throughout the Northeast and to compile the names of Moroccan cab drivers. Police officials and Mayor Michael Bloomberg have said the surveillance effort was legal, constitutional and vital to protecting the city after the 2001 terrorist attacks.

Ferhani’s lawyers lambasted the conduct of prosecutors, as well as police.

The defense attorneys said Monday that prosecutors had impinged on Ferhani’s communications with his lawyers by seizing the cellphone of a female companion — his lawyers say she is his common-law wife, while prosecutors term her his girlfriend. She had exchanged text messages with one of the lawyers, Lamis Deek, about questions Deek had for Ferhani, the lawyer said.

Prosecutors argue that attorney-client privilege didn’t apply to the messages to the woman.

Deek found herself in the spotlight earlier in the case, when prosecutors told a judge last fall that she had unknowingly represented the undercover detective in an unrelated matter. He used his alias and kept his cover when he went to her for legal help.

The defense charged Monday that prosecutors were trying to sideline Deek because of her heritage; she is a Muslim of Palestinian descent. Manhattan Assistant District Attorney Gary Galperin called the claims “outrageous accusations and hyperbolic political rhetoric.”

Prosecutors “are confident that we have acted within the realm of the law and our ethical obligations,” he said.

Ferhani and Mamdouh are being held without bail. Mamdouh has a court date Wednesday. Ferhani is due back in court in September.