The NYPD has had a stellar track record of protecting the city from another 9/11, foiling more than 20 planned terrorist attacks since 2001. But some worry the department is losing its terror-fighting edge as it tries to please Muslim grievance groups.

Last year, for instance, it censored an anti-terror handbook to appease offended Muslims, even though it has accurately predicted radicalization patterns in recent “homegrown” terror cases. Rank-and-file NYPD officers, detectives and even intelligence and counterterrorism units are officially barred now from referring to the handbook or the scientific study on which it was based.

Former law-enforcement officials fear its removal as a training tool may be hurting efforts to prevent terrorist activity, such as the vehicle-ramming attacks plaguing European cities.

“The report was extremely accurate on how the radicalization process works and what indicators to look for,” said Patrick Dunleavy, former deputy inspector general of the New York state prisons’ criminal-intelligence division, who also worked with the NYPD’s intelligence division for several years.

Mayor de Blasio agreed in January 2016 to purge the remarkably prescient police training guide “Radicalization in the West: The Homegrown Threat” to help settle a federal lawsuit filed by the ACLU and Muslim groups who claimed the NYPD’s anti-terror training discriminated against Muslims.

Written 10 years ago, the seminal NYPD report detailing the religious steps homegrown terrorists take toward radicalization is now more relevant than ever, with recent terror suspects closely following those steps. But in 2007, the same year the study was released, the Council on American-Islamic Relations (CAIR) organized a protest against it, complaining it “casts suspicion on all US Muslims.” Even though federal law enforcement has long-shunned CAIR as a suspected terrorist front organization, “groups like CAIR were insistent on having it removed, and de Blasio caved into them,” Dunleavy said.

Under the city’s unusual settlement agreement, the NYPD as well as New York state agencies were forced to remove its 90-page anti-terror study — described by plaintiffs as “deeply flawed” and “inflammatory” — from databases and no longer rely on it “to open or extend investigations” into terrorist activities. Also, police must now commit to “mitigating the potential impact” of any counterterrorism investigation on the Muslim community.

The deal has had a chilling effect on other city police forces’ ability to use fact-based, trend analysis to develop terrorism cases, experts say. They warn that purging such studies deprives local law enforcement of the ability to understand how ISIS and other jihadists recruit, organize and operate — which is critical to disrupting terrorism plots.

“The FBI has its hands full with over 1,000 open cases on ISIS terrorist suspects already in the US,” former FBI Agent John Guandolo said, “and it needs the help of well-trained eyes and ears on the ground at the local and state level.”

“The bad guys know if police don’t know this stuff at the ground level, they win,” added Guandolo, who trains sheriffs departments across the country to ID local jihadi networks through his consulting firm, Understanding the Threat LLC.

The authors of the report, led by Mitch Silber, former NYPD director of intelligence analysis, examined hundreds of “homegrown” terrorism cases and found that suspects followed the same “radicalization” path. Key indicators include: alienating themselves from their former lives and friends; giving up cigarettes, drinking and partying; wearing traditional Islamic clothing; growing a beard; becoming obsessed with Mideast politics and jihad; and regularly attending a hardline mosque. In other words, the more they immersed themselves in their faith, the more radical they grew.

‘The ultimate objective for any attack is always the same — to punish the West, overthrow the democratic order, re-establish the caliphate, and institute Sharia’

“You can take all the terrorist cases since that report and compare the information on the subject and the case and see stark similarities to what Mitch laid out,” Dunleavy noted.

The terrorists who carried out recent attacks in Boston; Fort Hood, Texas; Little Rock, Ark.; Chattanooga, Tenn.; San Bernardino, Fla.; Orlando; Philadelphia and at Ohio State University, among others, followed a similar pattern of radicalization. In each case, the Muslim attacker was influenced through “incubators of extremism” within the Muslim community, including Islamic student associations, schools, bookstores and mosques. Jihadi websites also played a role, but what unifies them all is Islamic doctrine. As the NYPD study found, “The ultimate objective for any attack is always the same — to punish the West, overthrow the democratic order, re-establish the caliphate, and institute Sharia,” or Islamic law.

“The radicalizer is Sharia, not the Internet,” said Philip Haney, a former Homeland Security counterterrorism analyst. Haney says the feds are plagued by their own PC censorship. Bowing to pressure from CAIR and other Muslim groups, Homeland Security and the Justice Department have purged anti-terrorism training materials and fired instructors deemed offensive to Muslims. CAIR-launched protests also helped convince the FBI to recently suspend an Internet program aimed at preventing the radicalization of Muslim youth.

“If we fail to correct this situation, it is inevitable that more attacks will occur,” warned Haney, author of “See Something, Say Nothing.”

The NYPD did not respond to requests for comment.

Paul Sperry, a former Hoover Institution media fellow, is the author of several books on terrorism including the best-seller “Infiltration.”