Tonight, Alabama did not elect a man accused of preying on children who thinks Muslims should not be allowed to serve in Congress. That's not the highest bar I can imagine for a democracy to clear, but I'm glad we cleared it.

But tonight’s election results do not leave me comfortable with the state of American politics. If Moore had merely been a candidate who believed Muslims shouldn’t be allowed to serve in Congress, that the laws of the United States of America should be superseded by his interpretation of the Bible, that homosexuality should be illegal, he would have won in a landslide. Even multiple credible reports that Moore serially preyed on teenage girls were barely enough to lose him the election.

Like Donald Trump before him, Moore is proof that there is no depravity so unforgivable, no behavior so immoral, that it assures a candidate will lose his party’s voters. What cannot be condoned will be denied. What cannot be denied will be ignored. What cannot be ignored has not yet been discovered.

Donald Trump was caught on tape bragging about sexual assault. Roy Moore was banned from the local mall. These were not loose allegations or flimsy rumors. They were consistent patterns of behavior, reported by multiple unconnected victims, corroborated by the candidates’ own actions and words. And still, exit polls found Moore held 91 percent of the Republican vote — likely because fully 44 percent of voters said they didn’t believe the allegations against him at all.

It is an oddity of election punditry that swings of a few percentage points in the vote produce analyses that are violently different in their assessment of the country’s mood and psyche. If Roy Moore had run a better field operation, and if Doug Jones had run a slightly worse one, tonight’s result would have flipped, and so too would the rhetoric. If Alabama’s election, like US presidential elections, could be won by the loser of the popular vote so long as that candidate ran particularly strong in rural areas, then Moore, like Trump before him, would have won.

This is not to say Jones’s win isn’t striking. It is. Moore would have prevailed by double digits absent the revelations about his sexual past. But the fact remains that even with all we learned of him, he is only projected to lose by about 1.6 points. Even though we are not the country that elected Roy Moore tonight, we are the country that almost elected him, and that is still worth reckoning with.

The flaw in America’s political system

The most important concept for understanding what has gone wrong in American politics is political scientist Julia Azari’s observation that this is an age of weak parties and strong partisanship. I have come to think of this as a flaw in the software of American democracy, a vulnerability that can be exploited to send malware ricocheting through the system.

Parties were traditionally bulwarks against demagogues rising in American politics — they were controlled by gatekeepers who acted as checks against charismatic demagogues. Trump would never have made it through the convention horse-trading that used to drive nominations; Moore would never have survived a process that required support from party officials.

But in recent decades, we have slowly destroyed the ability of party officials to drive party primaries. What’s more, we have come to see party officials exercising influence as fundamentally illegitimate. Most Alabama Republicans said Mitch McConnell’s opposition to Moore made them like him better.

And now, once a candidate, even a controversial candidate, wins their primary, partisanship takes over, and they consolidate their base, and they can win. Partisanship is so powerful that it will even lead us to dismiss information we dislike, to live in a world of our own imagining so long as we don’t have to support a candidate of the other party.

This is the bug in the American political system, the security flaw in our software. It is why Moore almost won tonight. It is why Trump won in 2016. And we still don’t have an answer for it. We can’t trust that all unfit demagogues will turn out to be predators.