A get-out-the-vote event at a Brooklyn synagogue featuring the comedian Ilana Glazer was canceled on Thursday night after anti-Semitic graffiti, including the words “Die Jew Rats,” was discovered scrawled on the temple’s walls, the police and officials at the synagogue said.

The vandalism, which is being investigated as a hate crime by the Police Department, jarred residents in a deeply progressive area of Brooklyn. It occurred on the heels of the mass shooting at a Pittsburgh synagogue last week and a recent spate of similar graffiti incidents in Brooklyn and Manhattan.

The police announced Friday night that they had arrested a 26-year-old man, James Polite, on charges that he wrote the anti-Semitic graffiti. He faces charges of criminal mischief, which the police classified as a hate crime, and making graffiti. Mr. Polite was taken to a hospital in Brooklyn for a psychiatric evaluation.

Earlier in the day, the police released a photograph of a suspect, taken by a security camera inside the temple.