A group of people who had attended an anarchist book fair in Manhattan later marched to a nearby Starbucks on Saturday night and began swinging at the windows with metal pipes, as frightened customers hid under tables, the police said.

The confrontation ended with three arrests and minor injuries to two police officers, the authorities said.

The police said the episode began near Washington Square Park, as a number of people who had attended the nearby book fair began to march in the street, against traffic, chanting anti-police slogans like “cops are murderers” and “all pigs must die,” according to the police. A witness, Obenjii Johnson, 19, who was riding a skateboard as the group passed, said he heard them shouting the names of Sean Bell, who died in a hail of 50 police bullets in Queens in 2006, and Trayvon Martin, who was killed by a neighborhood watch coordinator in Florida this year.

The ranks of the demonstrators swelled to 150, with many wearing masks and black clothing, the police and witnesses said.