Barack Obama had a choice between liberalism and the Democratic Party. He chose the latter — and it cost him dearly.

Liberalism, as an ideology, insists that government can do good and great things for the people and the world, if the people running the government are smart liberals.

The Democratic Party says the exact same thing. But liberalism is an ideal, while the Democratic Party is that ideal’s representative here in the real world, and in the real world political parties disappoint.

Just to be clear — and to avoid a lot of “Oh, yeah? What about Republicans?!” responses — this is true of the GOP, too. Conservative ideology holds that government should only do those things that only government can and should do, and that list is very short.

For instance, government shouldn’t be in the business of playing favorites in the economy. It shouldn’t “pick winners and losers.” Rather, it should be a fair umpire and let competition work its magic.

Alas, Republican politicians routinely fall short of this ideal, preferring to be pro-business rather than pro-market. That, in so many words, is why the Export-Import Bank is immortal.

But this was supposed to be liberalism’s moment. This was supposed to be a new Progressive Era.

Obama came into office vowing to be “transformative” just like Ronald Reagan. The difference being that Reagan ushered in an era of skepticism about government, and Obama wanted to usher in an era of hope and idealism about all the wonderful things government can do.

In Obama’s mind this put him at odds with Republicans. And in a partisan sense it obviously did.

But as a matter of policy, Obama’s real challenge came from within. Government’s failures in recent years can’t be laid at the feet of the Republican Party but at the feet of the Democratic Party.

Ask most serious liberal policy wonks how they’d make government more effective, and a good number of their answers would involve doing things the Democratic base would never, ever allow.

Smart liberalism has no love for bureaucratic inefficiencies. There’s nothing inherent to liberalism that says public-sector unions should have a stranglehold on the government payroll the way they do. FDR loathed the idea of government workers unionizing.

The biggest threat to job security at most federal agencies is death. Incompetence, negligence and redundancy are rarely seen as cause for termination.

In 2010, the dismissal rate for 168,000 federal workers in the Washington, DC, area was .26 percent. That’s point-two-six, not 26 percent or 2.6 percent.

Local governments are little better. Short of murder or pedophilia, there’s almost nothing a tenured public-school teacher can do that will get him or her summarily fired. Read all the Keynes, Schlesinger, Lippmann, Galbraith you can. You’ll find nothing in there that even hints this is the way things ought to be.

If Obama wanted to restore faith in government, he’d have pushed for mercilessly firing bad government workers and ending stupid programs. He paid a little lip service to such things, but his priorities were all in the other direction.

That is because he had to dance with the girl that brung him.

The Democratic Party isn’t simply the party of government, it’s the party for government. That’s why his stimulus package was top-heavy with bailouts for federal programs, state governments and public-sector workers.

When he finally learned that there are no such things as “shovel ready jobs,” it should’ve prompted him to ask, “Why not?” The answer would’ve led him to reforms that undoubtedly would have helped the American people — and the cause of liberalism! — but hurt his own base in the Democratic Party.

On Obama’s watch, we’ve seen horrifying incompetence, malfeasance or skulduggery at the Department of Veterans Affairs, Immigration and Customs Enforcement, the IRS, Justice Department and Health and Human Services.

Republicans didn’t create the fiasco of the ObamaCare rollout; the architects of ObamaCare did that all by themselves. Just this week, the wheels came off the bus at the Secret Service.

You can denounce the anti-government rhetoric of Rand Paul, Ted Cruz and the Koch brothers all you like, but they didn’t cause any of these spectacular failures.

Obama set out to restore faith in government and liberalism. He ended up throwing them both under the bus for the sake of his party.