This is a story about American democracy working. It features bipartisanship, compromise in the public interest, competent public servants and responsiveness to voter will.

Of course, therefore, it’s not a story about the Republican-controlled Congress or the Trump administration. Nor has it quite yet come to a happy ending.

Still, it is a true story. And in these days when cynicism about our politics can seem all too justified, it might cheer you up and even offer a lesson or two.

The subject may sound mundane: paying for the public transit system of the Washington, D.C., region. But another way of putting it would be: Can elected governments — in this case of one city and two states, each with governors and legislatures of different parties — come together to ensure that the nation’s capital remains a viable place to live and do business in the 21st century?

Or, rephrased one more time: Can American politics still work?

For years, many people (including us at The Post’s editorial board) have been pointing out that Metro is the only big-city transit system without a dedicated source of funding, such as a penny sales tax that automatically goes to transit. That means that the Washington Metropolitan Area Transit Authority has gone begging every year, year after year.

That translates to insufficient funding — which shows up as delayed trains, broken escalators and other indicators of decline.

For just as many years, the warnings have been ignored. Politicians don’t like to raise taxes, especially for the essential but unsexy purpose of maintenance and repair.

But here we are: Virginia this month approved permanent funding, Maryland is expected to follow this week, and the District shortly thereafter. For the first time in its 42-year history, Metro will have a dedicated source of funding for capital maintenance and improvements.

What happened?

Politicians from each jurisdiction will tell you that they deserve the credit — and in a sense, they’re each right.

Maryland Gov. Larry Hogan, a Republican who initially balked at committing additional funding, had the good sense to shift positions last fall and challenge the other jurisdictions to put their money on the table.

Virginia Gov. Terry McAuliffe, a Democrat, committed to full funding before he left office, and his successor, Democrat Ralph Northam, had the bipartisan chops to steer the proposal through a Republican-controlled General Assembly.

D.C. Mayor Muriel E. Bowser and council member Jack Evans, who doubles as Metro board chair, were always going to make sure the District did its part if the two neighboring states came through.

Now, you can say they were all just being political, and in a sense that would be right, too.

Republicans in Richmond saw their gubernatorial candidate lose and their legislative majorities dramatically shrink last year, and they understood that opposing Metro was not a smart position in vote-rich Northern Virginia.

Running for reelection this year, Hogan did not want to be painted as the anti-Metro candidate in the comparably vote-rich Montgomery and Prince George’s counties.

But “just being political” is a derisive way of saying they were listening to their constituents, as were legislators in all three jurisdictions — and their constituents, especially younger ones, value public transit more than ever.

“People get it,” Paul J. Wiedefeld, Metro’s general manager, told me in a conversation last week. “Even if they don’t use Metro on a regular basis, they understand it’s important to their quality of life.”

When the Washington region emerged as a finalist for Amazon’s second headquarters, and Amazon made clear that transit would be a major factor in its choice, that “crystallized how important Metro is in general,” Wiedefeld said — not because Amazon is so critical, but because virtually every business now wants to locate near Metrorail (rather than, as in past days, near a Beltway exit). (Disclosure: Amazon founder and CEO Jeffrey P. Bezos also owns The Post.)

And Wiedefeld himself was key. A former airport manager, Wiedefeld effectively hides a doggedness of purpose under a relentlessly mild-mannered demeanor. When he took over in November 2015, he quickly understood that the system was on an unsustainable path. But he also understood that it did not have the credibility to ask for more money. Only after he overhauled management, improved service, tightened the budget and showed he could be tough enough to shut the system when safety demanded it did he launch, last April, his appeal for sustainable funding.

A year later, improbably, he’s getting what he asked for.

The exact funding mechanisms may not be ideal. Metro still will have plenty of problems. But politicians will have done the right thing. The system will have worked.

Let’s take a moment to give thanks, before we go back to worrying about the end of the world.

Read more here: