A federal court said Tuesday that a civil rights lawsuit accusing police in New York City of improperly singling out Muslims for surveillance could proceed, reversing a lower court’s decision last year to dismiss the case.

In its opinion, a three-judge panel of the U.S. Court of Appeals for the 3rd Circuit rejected the city’s call to have the case dismissed and brushed aside any suggestion that media reports about the surveillance, rather than the surveillance itself, caused any harm.

Judge Thomas L. Ambro, who wrote the 59-page opinion for the panel, also cited dark chapters in American history — like the internment of Japanese Americans during World War II, for which the United States later apologized — as times when national security issues, civil liberties and wartime fears inexorably collided.

“We have learned from experience that it is often where the asserted interest appears most compelling that we must be most vigilant in protecting constitutional rights,” Ambro wrote.

The lawsuit claims that surveillance of Muslim people in New Jersey discriminated against them due to their religion. It was filed by Muslim Advocates, a legal advocacy group, and later joined by the Center for Constitutional Rights, another legal organization, on behalf of several New Jersey Muslims who say they were unconstitutionally monitored by the New York Police Department.

“I am so pleased the court recognized our claim that the NYPD is violating our basic rights as Americans and were wrong to do so,” Farhaj Hassan, lead plaintiff of the lawsuit, said in a statement released by the Center for Constitutional Rights. “No one should ever be spied on and treated like a suspect simply because of his or her faith, and today’s ruling paves the path to holding the NYPD accountable for ripping up the Constitution.”

The New York City Law Department said it was reviewing the circuit court’s decision.

“At this stage, the issue is whether the NYPD in fact surveilled individuals and businesses solely because they are Muslim, something the NYPD has never condoned,” a spokesman for the New York City Law Department said in a statement Tuesday afternoon. “Stigmatizing a group based on its religion is contrary to our values.”

The New York Police Department referred questions about the opinion to the law department.

Last year, the NYPD disbanded the unit involved in the surveillance activities, a move that Mayor Bill de Blasio (D) praised in a statement at the time as “a critical step forward in easing tensions between the police and the communities they serve.”

A judge in New Jersey had agreed last year with the city’s contention that the lawsuit should be dismissed.

Among other things, Judge William J. Martini of the U.S. District Court wrote that harm came only after reporters for the Associated Press wrote about the surveillance program in a Pulitzer Prize-winning series of stories. (Full disclosure: One of the Associated Press journalists who reported on the program, Adam Goldman, now works at The Post.)

In one story, published in February 2012, the Associated Press reported that the New York Police Department sent plainclothes officers to Newark businesses owned or frequented by Muslim people, took photographs of 16 mosques and mapped them.

Because the lawsuit did not claim any harm before the Associated Press began publishing stories about the program, it meant that any issues came “from the Associated Press’s unauthorized disclosure of the documents,” Martini wrote.

He also noted that the surveillance “may have had adverse effects upon the Muslim community after the Associated Press published its articles,” but said that any harm was not “‘fairly traceable’ to any act of surveillance.”

The appeals court panel was not moved by this argument, which Ambro characterized thusly:

In short, it argues, “What you don’t know can’t hurt you. And, if you do know, don’t shoot us. Shoot the messenger.”

Martini also wrote last year that the lawsuit did not not prove that people were targeted solely because of their religion.

“The more likely explanation for the surveillance was a desire to locate budding terrorist conspiracies,” he wrote, pointing out that the surveillance began after the Sept. 11, 2001 terrorist attacks. Martini added: “The police could not have monitored New Jersey for Muslim terrorist activities without monitoring the Muslim community itself.”

Ambro and the panel did not seem swayed by this suggestion. He wrote that even though New York City invoked national security needs, constitutional rights also need to be protected.

“What occurs here in one guise is not new,” Ambro wrote. “We have been down similar roads before. Jewish-Americans during the Red Scare, African-Americans during the Civil Rights Movement, and Japanese-Americans during World War II are examples that readily spring to mind.”

The case is Hassan v. City of New York.