Buildings shook and glass shattered as a bomb spewed shrapnel in Chelsea Saturday night.

First responders rushed in to help dozens of injured bystanders, and soon, an unexploded device was found a few blocks north.

Across the country at a Minnesota mall the same night, a man stabbed nine people before he was shot to death. In New Jersey earlier in the day, a pipe bomb exploded during a charity running race, but resulted in no injuries.

The incidents underscored a sense of vulnerability that New Yorkers are familiar with: Such violence could happen anywhere at any time.

The city coped quickly. Twenty-nine people who suffered injuries on 23rd Street were treated on the scene or at hospitals. All were soon released.

Setting a tone of measured preparedness, Mayor Bill de Blasio and new Police Commissioner James O’Neill urged the public to cooperate with law enforcement. O’Neill noted the department’s work in foiling 20 plots against New York City since 9/11.

Whether or not all 20 of those plots were true threats to the city, the NYPD is well-suited to thwart organizations plotting large-scale attacks. But there seems to be little law enforcement can do to stop smaller attacks and less organized actors, no matter what grievance inspires their violence. That was true in the bombing at the Boston Marathon in 2013, and when a car bomb failed to detonate in Times Square in May 2010.

Saturday’s bombing could have been far worse. Defending against similar attacks, be they terrorism foreign or domestic, is very difficult. New Yorkers must help police with tips and cooperation. This event also shows how important it is for the NYPD to foster good relationships with all of NYC’s communities, making people comfortable to come forward. This kind of violence calls for careful investigation and diligent interagency cooperation.

Once again, officials asked New Yorkers to be vigilant. They will be, as they have been before. That cooperation is essential and must continue.