Roy Moore, who wants the US to return to the days of slavery, won nearly half of the votes in the Alabama Senate race.

On Wednesday, Republican Judge Roy Moore, who had secured the backing of US President Donald Trump, lost the senate race in the conservative state of Alabama to his Democrat rival Doug Jones. Moore has been accused of rape and molesting a 14-year-old girl, and many believe these accusations cost him the election. But his was still a very narrow defeat, as the Republican candidate got very nearly half the vote.

The defeat of Moore is exciting at least because it shows that a Democrat can actually win an election. But it is also a matter for concern – if not despair – that his defeat only came over allegations of sexual misconduct.

In September, prompted by his support for Donald Trump’s claim to make “America great again”, he was asked the obvious question: When did he think the country had been great?

Moore said, “I think it was great at the time when families were united – even though we had slavery – they cared for one another … Our families were strong, our country had a direction.”

This is a kind of lunacy. How is it possible to say, “families were united” when slave owners could sell off a mother’s children? When they could separate husbands and wives? What does it mean to say that “families were strong,” when the infinite gradations of colour among African-Americans were being created by slave owners raping the women whom they owned. Their wives had to tolerate this, because men controlled all the property and money.

If some of the worst candidates in history can be nearly elected, it means that the backward logic and disguised appeal to pre-civil war racism and women as second class citizens without voting or property rights remain powerful and dangerous.

Back in 2011, Moore said the Amendments to the Constitution should have stopped with the first 10, called the Bill of Rights, and adopted at the same time that the Constitution was initially passed.

Keep in mind that the Constitution implicitly accepted slavery. Southerners – like Thomas Jefferson and James Madison – wanted it both ways, to keep blacks in slavery and yet have additional political power based on the number of slaves that were owned in their states. Their solution, written into the Constitution, was that “Representatives … shall be apportioned … according … to the whole Number of free Persons … [and] three fifths of all other Persons.” That last being a euphemism for slaves.

Had the US stopped after the first Ten Amendments, slavery would still be constitutional. It was the 13th Amendment that finally abolished it.

The 14th gave citizenship to anyone born or naturalised in the US and the 15th gave all males the right to vote regardless of race, creed, colour, or having been a slave. The 19th gave women the right to vote.

The 17th Amendment took the right to elect senators away from state legislators and gave it to the voters.

The 16th Amendment legalised federal income taxes and the 24th made the poll tax – a device to keep the poor, especially African-Americans from voting – illegal.

In 2006 Moore wrote an op-ed article that said, “To support the Constitution of the United States one must uphold an underlying principle of that document, liberty of conscience, which is the right of every person to worship God according to the dictates of his conscience, without interference by the government.” Then used that as an argument to say that Keith Ellison – who is a Muslim – should not be allowed to serve in congress. This is an inversion of reason and logic that makes Alice’s Adventures in Wonderland seem like essays in realism.

Roy is most famous for his putting up a massive monument to the 10 Commandments in the Alabama Supreme Court building as a statement that it is the basis for the US’s legal system. He is not alone in this. The late Justice Antonin Scalia said, “It’s a symbol of the fact that government comes – derives its authority from God.”

Yet if we actually compare the Ten Commandments to the first Ten Amendments, what’s striking is that the Constitution is a direct refutation of the ones that aren’t part of all standard legal systems, the rules against murder, theft, perjury, and adultery.

The First Commandment is “Thou shalt put no other God before me.” The First Amendment is that “Congress shall make no law respecting an establishment of religion.”

The second, “Thou shalt make no graven image and not take the name of the Lord they God in vain” is also opposed by First Amendment which says there shall be “no law abridging freedom of speech.” The Commandment to “honor they father and mother,” likewise comes up against the guarantee of free speech.

“Thou shalt not covet,” would make thoughts into crimes. The Bill of Rights call for adherence to “the rules of common law,” which require actus reus, an act, for something to be a crime.

In the end, Roy Moore lost the election. But his narrow defeat came only over allegations of sexual misconduct and not because he wants to return to the days of slavery, voting by white males only, and wants to impose a theocratic vision on the US.

Perhaps the tidal wave that put Trump in the White House and Republicans in control of all branches of government, has begun to recede. Perhaps Democrats can figure out how to keep winning elections. But if some of the worst candidates in history can be nearly elected, it means that the backward logic and disguised appeal to pre-civil war racism and women as second class citizens without voting or property rights remain powerful and dangerous.

The views expressed in this article are the author’s own and do not necessarily reflect Al Jazeera’s editorial policy.