Martini said he was not convinced that the plaintiffs were targeted solely because of their religion. "The more likely explanation for the surveillance was to locate budding terrorist conspiracies," he wrote.
The judge added: "The police could not have monitored New Jersey for Muslim terrorist activities without monitoring the Muslim community itself."
Farhaj Hassan, a plaintiff in the case and a U.S. soldier who served in Iraq, said he was disappointed by the ruling.
"I have dedicated my career to serving my country, and this just feels like a slap in the face — all because of the way I pray," he said.
The Center for Constitutional Rights in New York and the California-based civil rights organization Muslim Advocates, which represented the plaintiffs, also called the decision troubling.
"In addition to willfully ignoring the harm that our innocent clients suffered from the NYPD's illegal spying program, by upholding the NYPD's blunderbuss Muslim surveillance practices, the court's decision gives legal sanction to the targeted discrimination of Muslims anywhere and everywhere in this country, without limitation, for no other reason than their religion," CCR Legal Director Baher Azmy said.
The lawsuit followed a series of stories by The Associated Press based on confidential NYPD documents that showed how the department sought to infiltrate dozens of mosques and Muslim student groups in New York and elsewhere.
Martini faulted the AP for its use of the documents.
"The Associated Press covertly obtained the materials and published them without authorization," he wrote. "Thus the injury, if any existed, is not fairly traceable to the city."
The AP declined to comment on the ruling.
The city's Law Department also declined comment. Former Mayor Michael Bloomberg and former Police Commissioner Raymond Kelly had been staunch supporters of the surveillance programs, saying they were needed to protect the city from terrorist attacks.
A similar lawsuit filed in federal court in Brooklyn is still pending.