Incumbent Rhode Island Gov. Gina Raimondo (D) waves to supporters on Sept. 12 in Providence, R.I. (Elise Amendola/AP)

ONE OF the hardest tasks facing state and local governments across the country is to find sufficient resources to pay for both the services their people need today — police, schools, parks — and the pension benefits they owe their employees in the future. All too often, politicians have promised generous benefits to politically influential public-sector unions, safe in the knowledge that figuring out how to fund them will be up to some other elected official years later. Once those promises are made, they are often legally binding, making it very difficult to enact structural reforms even in jurisdictions that are at or near financial crisis. Employees and their unions fight tooth and nail to defend every dollar of what they consider, not unjustifiably, deferred compensation. Detroit, for example, did not overhaul its pensions until it actually entered municipal bankruptcy.

The politics of pension reform, in short, are brutal; most politicians prefer to find short-term patches and workarounds rather than attempt to restructure public-employee benefits for long-term sustainability.

An exception to this rule is Rhode Island’s Democratic governor, Gina Raimondo, whose bid for a second term received a boost Wednesday when she defeated a serious primary challenge to win her party’s nomination. Ms. Raimondo established her national reputation before she was elected governor in 2014, when she was still the state’s treasurer. In that position, she spearheaded a comprehensive pension reform proposal to rescue Rhode Island’s badly underfunded state plans. Basically, it froze annual cost-of-living increases for retirees while moving employees to a new system that combined a defined-benefit program with a 401(k)-like plan to which employees contributed. Enacted into law in 2011, the plan survived legal challenges — with some modifications — and has achieved progress. In the seven years before Ms. Raimondo’s plan, state spending on pensions had doubled while its funding ratio decline. Now contribution growth has moderated, and the funding ratio, a paltry 49 percent in 2010, has improved by several percentage points.

Ms. Raimondo’s reforms were no magic bullet. The state has not yet hit the short-term target of a 60 percent funding ratio, and the ratio actually shrank in the fiscal year that ended June 30, 2017, in part because of accounting changes but also because of lower than expected investment returns. Still, the most recent state actuary’s report puts the funding ratio on course to reach 80 percent around 2031 and 100 percent by 2038. In other words, the situation, though far from perfect, is better than it would have been without reform.

Opponents of Ms. Raimondo’s reform plan tried to use it against her, unsuccessfully, in her first campaign for governor; and her opponent Wednesday, Democrat Matt Brown, promised to reverse key aspects if elected. For the second time, Ms. Raimondo persuaded voters of her own party to support her nonetheless. She faces a potentially close race against a Republican and an independent in November. But her career thus far, bolstered by her decisive victory Wednesday, teaches an important lesson for politicians of all parties: Asking constituents to sacrifice for the long-term public good is not an electoral death sentence, at least not if the reform is shaped and led with professionalism, fairness, honesty and respect for all sides.