The savage beating of journalist Andy Ngo in Portland by far-left antifa rioters last Saturday shocked everyone. Well, conservatives anyway, plus a few honorable liberals. As the police stood by watching at a distance, masked thugs hit him, stole his camera and threw milkshake, rocks and eggs at him. He ended up in the hospital with a brain hemorrhage.

Criminal laws are supposed to deter criminal behavior. But that only works when the criminal gets caught and punished, and when people are permitted to hide their identities behind a mask, as antifa thugs are, no one gets caught.

Portland’s mayor, Ted Wheeler, has vowed to hold the offenders accountable. Let us know who the perpetrators are, he asked, and the city would hold them accountable — a supremely useless plea when dealing with a largely masked and anonymous group.

The antifa slogan in Portland is “we own the streets.” And they do. The city has let it happen. Last October, they blocked a street and threatened drivers and passers-by who wanted to get through. A few months before that, they beat up a Bernie Sanders supporter who was carrying an American flag.

And it isn’t just Portland. We saw similar brutality in Washington, during President Trump’s Inauguration. Hundreds of rioting antifa members took over downtown DC. They marched in black bloc fashion, five abreast, their faces wholly covered, smashing windows and pushing people off the sidewalk. The police arrested 234 people, but not one of them was found guilty.

It’s the masks that save them. They’re a get-out-of-jail-free card. Deterrence doesn’t work when you can hide your identity. That’s a lesson we should have learned from the Ku Klux Klan.

Thanks to the masks, antifa won’t pay a cost. Instead, they will luxuriate in their sense of justified political hatred. They will also have the backing of prominent apologists in the liberal establishment, including Minnesota Attorney General Keith Ellison, who endorsed the antifa handbook, and CNN’s Don Lemon, who said in defense of the group that “no organization is perfect.”

Best of all for antifa, their actions have an effect. They are letting conservatives and even dissident liberals like Ngo know that they aren’t safe in Portland.

Mind you, that only works if the state is complicit. And when the city abandons its duty to protect its citizens, its inaction amounts to permission.

Mayor Wheeler is picky about the people he will protect. When a federal immigration building was surrounded by protesters last summer, its workers feared for their safety. But the mayor supported the protesters, and, following his orders, the local police refused to take sides.

The Immigration and Customs Enforcement workers were effectively imprisoned in their building until federal forces from Homeland Security arrived to rescue them. When it was over, Homeland Security installed a “no-climb” fence to protect the ICE workers, to which the city objected because it was too high.

Wheeler says he is against violence. But the hooded antifa riots are still tolerated. The Portland police chief wants to ban masks, but fat chance the state will pass such a law, against protests by civil libertarians. And an anti-mask law isn’t necessary. The state already has a perfectly suitable remedy, in its anti-riot law. A person commits the crime of riot if, while participating with at least five other people, he engages in tumultuous and violent conduct and thereby intentionally or recklessly creates a grave risk of causing public alarm.

I can’t think of a better definition of the antifa method of operation.

After Ngo was beaten, the police declared a riot. Next time, the riot should be declared the moment hooded antifa protesters show up. But Wheeler won’t let that happen. That would get in the way of antifa’s free-speech rights, he thinks.

Evidently, it’s time for the federal government to step in — and crack down. It has had to do so in the past, especially during the civil rights era in the South.

There’s a federal law against conspiring to injure or intimidate a person in the free exercise of enjoyment of his rights or privileges, and I should think the elements of the offense are complete the moment the antifa goons show up in Portland.

What’s missing is the will to protect ordinary citizens, and since the city of Portland won’t do so, it’s time for federal marshals or the FBI to step in.

F.H. Buckley teaches at Scalia Law School and is author of “The Republican Workers Party: How the Trump Victory Drove Everyone Crazy, and Why It Was Just What We Needed.”