Vital services: Victims of flooding and fire from Hurricane Sandy getting a ride from an NYPD truck the day after the storm.AFP/Getty Images

Vital services: Victims of flooding and fire from Hurricane Sandy getting a ride from an NYPD truck the day after the storm. (AFP/Getty Images)

One of the few positive effects of Hurricane Sandy was that it reminded New Yorkers how much they need the police.

For weeks before the storm, the cops had been subjected to a bombardment of criticism. Some complained about them stopping and frisking supposedly innocent people. A high-profile lawsuit alleged that they charge individuals with trespassing in public-housing areas who are actually residents or legitimate visitors. Then there were cries about police being heavy-handed in dealing with disorderly groups that try to take over public spaces.

No one would argue that police conduct is always correct. Yet the test in matters like searches or arrests isn’t some politician’s or activist’s opinion, but whether the action is “reasonable.” In judging this, panels of learned jurists, deliberating in a calm atmosphere, often can’t agree. Thus it is no surprise that police officers making split-second decisions in fast-moving, dangerous situations, sometimes are mistaken.

The effectiveness of stop and frisk tactics perhaps explains why New York City this year will likely record the fewest number of murders in more than half a century. In contrast, in cities like Chicago, the murder figures are going through the roof.

And the NYPD’s much-criticized enhanced public-housing security actually came at the request of residents seeking protection from predators who roam the halls and grounds. Similarly, crowd-control tactics are meant to prevent disorder from erupting. Even peaceful crowds can turn violent: Recall the riot after the 1983 Diana Ross concert in Central Park.

But Sandy’s onslaught put proactive law enforcement in a different light. New Yorkers were delighted to see police engaging in vigorous patrol, particularly in areas like the blacked-out housing projects. Even gas stations had to have officers stationed on-site as fights broke out on the long lines. When officers jumped in quickly to separate combatants, there were no complaints about excessive use of force. Everybody wanted the disorder stopped before someone got hurt.

Tragically, other recent incidents illustrate how dangerous the police job is. In one instance a Nassau County officer, patrolling near the New York City limits, made a routine traffic stop and was shot to death.

A few days later, an off-duty NYPD officer intervened in a holdup; shot and wounded by the perp, he still managed to capture the robber.

As Sandy demonstrated, public attitudes toward policing can change quickly. After the 9/11 attack, which left nearly 3,000 people dead in New York, the public didn’t want to hear any criticism of the heroes in blue. In the first decade of the new century, Commissioner Ray Kelly’s accomplishments in crime-fighting, anti-terrorism and community relations won considerable applause. Yet now those successful programs are under attack.

We’re heading into a mayoral election year, so it will likely be open season on the NYPD. But politicians who play the cop-bashing game should realize that unfair attacks, often based on false premises, can demoralize the police and make them less effective in carrying out their duties.

Recall the mayoralty of John Lindsay (1966-1973), who rarely missed an opportunity to criticize the NYPD. Not so coincidentally, Lindsay’s tenure was plagued by riots, corruption, scandals and escalating crime; the annual number of murders rose over 160 percent. When Lindsay left office, his once-promising career was in shambles.

The new mayor and City Council who take office on Jan. 1, 2014, may find themselves in charge of a police department demoralized by constant attacks, which could lead to a repeat of the crime and disorder of the Lindsay era.

Policing can always be improved, but it will be done best by a city administration that inspires and guides the cops — not one that constantly bashes them.

Thomas A. Reppetto is the former president of the Citizens Crime Commission of New York City and the author of “American Police: A History, 1945-2012.”