San Jose, in the heart of Silicon Valley, is home to eBay, PayPal and Cisco. Yet despite its enormous wealth, a San Jose house right across from a fire station burned down in 2013 because the station lacked fire trucks.

This year, police staffing is down in San Jose. Its roads are pocked with potholes. And again, fire engines are mothballed. How is all this possible?

The answer is that nearly 25 percent of San Jose’s budget pays for generous pensions—called “defined-benefit” plans—that guarantee retired city workers as much as 90 percent of their former salaries for life. That has left too little for core city services like policing and firefighting.

California’s experience offers vital lessons for New York.

In San Jose, pension costs exploded from $62 million in 2003 to nearly $210 million in 2013. So even though the San Jose Police Department budget skyrocketed nearly 50 percent during the past decade, police staffing fell 20 percent—because so much of the money was eaten up by the pensions.

Marin County, north of San Francisco, is also battling exploding pension costs. Home to “Star Wars” creator George Lucas, Marin is the wealthiest county in California. But its public-school teachers are members of the California State Teachers’ Retirement System, a defined-benefit pension system that’s $104 billion in debt.

To fill this gaping hole, the California legislature and Gov. Jerry Brown jacked up the amount school districts must pay to the CalSTRS fund each year by a whopping 132 percent. Marin will see its outlays soar to $36 million in 2020, from just $15 million in 2014. “I have no idea where we’re supposed to get the money,” one exasperated school official in Marin County says.

Pouring additional millions into pensions leaves school districts with less money to hire new teachers, repair school buildings and provide for the classroom needs of children.

Pension payments to CalSTRS from all California school districts will increase to $6.4 billion in 2021, from $2.3 billion in 2015—a nearly threefold increase. These higher costs will drain school budgets for more than 30 years. Yet, shockingly, CalSTRS CEO Jack Ehnes wants to hike teachers’ pension benefits by another 50 percent.

California’s experience offers important lessons. First, wealthy communities nationwide are not immune to deep cuts in basic public services when the pension “hogzilla” attacks.

The history of government pension plans is one of politicians overpromising benefits, underpaying pension funds and pushing mountains of debt onto future generations. Schools and communities are stuck bailing out the mismanaged plans, usually by squeezing services.

Second, with politicians and bureaucrats sacrificing education and public safety to prop up failed pension systems, they’ve passed the moral tipping point. Former San Jose Mayor Chuck Reed explains the unfairness: “I am cutting services to my low- and moderate-income people . . . to pay really generous benefits for public employees.”

This is clearly immoral.

Yet the same story may soon unfold in New York. Here, state and local governments have promised $308 billion more in pension benefits than what’s in their pension funds. That’s a $15,000 debt for every New Yorker. California’s pension debt is nearly $20,000 per resident.

To make ends meet, more and more communities may have to roll back core services.

Fortunately, there’s a solution.

California, New York, New Jersey and other states can switch to 401(k)-style pensions for teachers, police officers and other public employees. These are the kinds of plans that are most common today in the private sector. Mr. Reed is advancing a 2016 statewide ballot measure in California to begin this switch.

With 401(k)s, government employees own and invest their own pension money. As with private-sector pension plans, employees are guaranteed fixed payments from their employers—but not specific benefits at retirement. So taxpayers can never be on the hook for funding gaps, because 401(k)s are always fully funded.

Also, with 401(k)s, government pension costs are easier to project and control. Benefits can be adjusted based on economic and market realities.

The savings from switching to 401(k)s would allow current pension debts to be paid off quickly. For California, New York, New Jersey and elsewhere, it’s a vital step toward sparing future generations the pension pain too many schools and communities are feeling today.