All together now: We like democracy because … why? The pathologies of the U.S. version are so obvious in the aftermath of the latest averted crisis that we need to ask ourselves whether it’s worth it — and why electoral democracy hasn’t self-destructed before. Should Tunisians or Egyptians opt for the Chinese model, where rational autocrats may restrict rights but where no one threatens to blow up world markets in the name of an 18th-century tax protest?

There is an answer: Democracy is self-correcting, at least where it works. The key to the process is a version of supply and demand. When a politician acts in a way that doesn’t serve the voters’ interests or desires, demand for that person’s services should decline. Another candidate who fills the demand will get elected.

Some democratic systems do this at the level of the individual candidate, some at the level of the party. In a winner-take-all district-based system as in the U.S. Congress, the market is structured to drive elected officials toward the median voters in their districts, and a two-party system usually emerges.

In a proportional-representation parliamentary system, the market allows for multiple niches of interest-based parties, which then form coalitions that satisfy their voters’ policy preferences.

So why isn’t the U.S. system working as it usually does to produce moderate elected officials?

As recently as the 1990s, critics of two-party democracy charged that its virtue was actually a flaw: that the Democrats and Republicans were so similar that they were indistinguishable on core economic issues, that the U.S. had no meaningful liberal (or conservative) option to satisfy the voters who wanted radical change.

Then came the tea party movement, born of two shifts in U.S. politics. One is a growing demand among some voters for meaningful fiscal discipline. After the George W. Bush administration failed to reduce the deficit and even expanded discretionary spending, some Republican voters decided their party’s mainstream couldn’t be trusted to achieve this aim. The party of Bush was, after all, acting as the model predicts, aiming itself toward the median voter and therefore not cutting popular social welfare programs.

The tea party movement began as a challenge within the Republican Party by members who weren’t seeing their preferences served.

Under ordinary circumstances, the party would’ve had to balance this internal pressure against the necessity of capturing the median voter — a challenge, to be sure, but perhaps not an impossible one.

Yet here the second weird feature entered the picture. During roughly the same period of the Bush administration, Republicans captured control of the legislatures in many majority-Republican states. Once in office, they systematically redistricted (polite word for gerrymandered) to assure safe Republican seats in Congress, dividing Democratic voters among majority Republican districts.

Democrats challenged these changes in the courts — and lost. The U.S. Supreme Court held, more or less, that political gerrymandering was part of the game, permissible so long as it wasn’t motivated by race. This posed a technical challenge for redistricters, because black and Latino voters skew Democratic.

Their ingenious solution, which was consistent with the letter of civil rights law, was to create Democrat-dominated districts that would elect racial minorities, keeping the numbers of minority representatives stable while still reducing the number of Democratic districts.

The result was that many gerrymandered Republican districts emerged where the median voter stood far to the right of the median voter in the state, or the nation.

Some of this rightward shift would have happened naturally as a result of the clumping that occurs as people choose to live near others who share their views. Distinguishing the effects of clumping from those of redistricting is tricky.

But the outcome is clear: Safe Republican districts gave us the tea party. This is why the tea party is so much stronger in the House than in the Senate: Senate districts are states, which can’t be gerrymandered.

Freed from chasing the median national voter, tea party representatives could move far to the right without fear of being voted out of office. The motivated voters who showed up for primaries pushed out more moderate Republicans still playing the old game. The disastrous consequence for Republicans is a self-perpetuating party-within-a-party that doesn’t care if it makes the wider party unelectable nationally.

Tea party supporters think they are fighting for the Republican soul, and they are: If they win, they will drive the party so far from the median voter that a Republican president will become unimaginable.

In theory, this problem should be self-correcting, as Republican voters realize that protest politicians won’t serve their real interests, and replace them with moderates more willing to compromise.

If this doesn’t occur, the Republican national leadership will have to push for further redistricting at the state level to help elect more moderate party members.

If neither of these things happens, the Republican Party will wither and die. It can’t sustain itself as a permanent minority party that can’t elect a president. A new, more moderate alternative to the Democrats will arise.

It’s happened before. The market may need time, but it will shake out.

So if you’re wondering why the U.S. keeps democracy, you have your answer. Markets inflict pain, but over time they tend to connect consumers with what they want.

Noah Feldman, a law professor at Harvard University, is a Bloomberg View columnist.