About three minutes of the encounter were captured on cellphone video; the footage showed just how close the police were to ending the episode with an arrest and how it suddenly spiraled back out of control, ending with a single shot that is heard but not seen on the video clip.

The shooting, coming days after the grand jury decision in the death of Eric Garner, drew immediate attention from Mayor Bill de Blasio and Police Commissioner William J. Bratton, who moved quickly to provide an account of the episode. They said the attack was not an act of terrorism and that it did not appear to be motivated by bias, though they said the Police Department would, out of caution, step up security at synagogues around the city.

The Police Department said Mr. Peters, 49, of Valley Stream, on Long Island, had been deemed an emotionally disturbed person during earlier encounters with the police. In an interview, the man’s sister said he had bipolar disorder and had stopped taking his medications.

But no one could explain what took Mr. Peters to the synagogue shortly after 1:30 a.m. on Tuesday, the third time he had gone there in less than 12 hours. Nor was it clear what prompted him to stab Mr. Rosenblat or to shout, according to Nathan Meir Spater, 34, a student from Tel Aviv, “I kill you, I kill you.”