A fire burns in Baltimore after protesters clashed with police on April 27. Lloyd Fox/Baltimore Sun

If nothing else, the violence in Baltimore has put every town in America on notice: It can happen anywhere — be prepared.

The deployment Tuesday of the Maryland National Guard and the imposition of a week-long curfew seemed to have brought a tense calm to Baltimore’s streets, after Monday night’s rampage of rioting, arson and looting.

President Obama may have helped by publicly denouncing the rioters — and demolishing the idea that this was a legitimate response to the death in police custody of 25-year-old Freddie Gray.

“When individuals get crowbars and start prying doors open to loot,” the president said, “they’re not protesting. They’re not making a statement. They’re stealing.”

Moreover, he stressed, they’re “destroying and undermining businesses and opportunities in their own communities.”

Mayor Stephanie Rawlings-Blake insisted, “We were engaged and working and managing the crisis.” But the video footage suggests a far different story.

Former New York City Police Commissioner Ray Kelly has dealt with similar situations. He noted “a lack of proactivity on the part of the [Baltimore] police.”

The rising violence certainly seemed to catch city officials completely unaware, despite multiple warnings. The mayor admitted early Monday that her earlier directive that cops give protesters room to conduct peaceful vigils had been exploited by “those who wished to destroy” — yet police still held back for much of the day, reluctant to engage.

In short, City Hall gave no sense it was in control of the situation.

New York has faced its own incidents of peaceful rallies sliding into riot, but this city has learned the lessons. That’s why the recent demonstrations here in the Eric Garner case, far larger than anything seen in Baltimore, remained largely peaceful and without incident.

Protest can always turn violent — whether in a city of 620,000, like Baltimore, or a town of 21,000, like Ferguson, Missouri. In the end, the impetus to stop the violence has to come from within the local community.

But violence is best headed off at the start — and now no official has any excuse left for not being ready.