Mayor Bill de Blasio deserves much blame for the city’s recent rash of violence by the mentally ill. But Gov. Andrew Cuomo’s actions — and lack of them — have played a big role, too.

One statistic is telling: With 19.5 million residents, New York has less than 3,000 beds available in state psychiatric hospitals — just 15 beds per 100,000, when the minimum ratio generally considered necessary is 50 per 100,000. In 1955, the state had 600 per 100,000, as mental health expert DJ Jaffe has reported — 40 times today’s level.

Cuomo has closed hospitals and let the number of psychiatric beds drop, but the mentally ill haven’t disappeared. They’re just swelling shelters, jails and prisons, sprawled out on sidewalks — or roaming the streets, creating mayhem.

The city just saw Randy Santos allegedly fatally bludgeon four homeless men and Kwesi Ashun smash a cop with a metal chair — plus at least two scary subway pushers.

It was a case like one of those last horrors that led New York to adopt Kendra’s Law, which lets judges order sick, potentially dangerous people to get treatment. It’s proven highly effective — but the Assembly refuses to go along with closing loopholes and making it permanent. Cuomo should hold Assembly feet to the fire and get the law strengthened.

The Legislature also needs to remove obstacles to committing mentally ill people who pose a serious threat. Most states set a “need for treatment” or “grave disability” standard; New York is one of just a few requiring someone to be a danger to himself or others.

As Jaffe argues, “Laws should prevent violence, not require it.” Yet when Ashun’s sister told a city Mobile Crisis Team she feared he might hurt someone, they told her to call 911 if he did. Uh, that would be too late.

Fact is, like de Blasio, Cuomo and the Legislature simply haven’t made serious mental illness a priority. It’s not just the sick who are now paying the price.