The NYPD is hoping to identify and treat mentally ill people who are prospective terrorists but can’t legally be searched or arrested, the NYPD’s top official for intelligence and counterterrorism said Wednesday.

Absent behavior that meets the legal threshold for measures such as search warrants or arrest, the aim is to connect a person who is sick and potentially dangerous “to counseling help or something else,” said Deputy Commissioner John Miller.

The challenge, Miller said, is “How do you find these people” and what should authorities do “if you can’t arrest your way through that problem?”

“We’re working with a number of organizations, including the FBI, on how to develop something short of booming the door, search warrants, arrests, when that might not stick, but we can bring the person back in a better direction,” Miller told an audience of business leaders during a breakfast meeting of the Association for a Better New York at the Roosevelt Hotel in Manhattan.

Miller cited the case of Zale Thompson, who in 2014 attacked police officers in Jamaica, Queens, with an ax. Thompson, who was shot dead at the scene, initially had been involved with black separatists. When the leader of his group rejected violence against the police, Thompson became an adherent of a violent ideology sympathetic to the Islamic State and Al Qaeda.

“He just changed channels. He changed to the terrorist narrative of ISIL and Al Qaeda, because that fit the script he needed to go by: ‘I want to act out in violence, cause I’m not making it in my life,’” Miller said. “So he is a good example of a guy who was probably a terrorist in terms of ideology, by convenience and probably also mentally ill.”

Miller did not elaborate on the NYPD’s nascent program, including whether the person under suspicion could be compelled to seek mental health care.