Doug Jones’s victory over Roy Moore in Alabama’s special Senate election is a victory for decency over indecency. Mr Jones deserved to win for reasons of morality alone. The contest should have been an open-and-shut decision. Alabamians had to choose between a Democrat who convicted two Ku Klux Klansmen for their roles in the notorious 1963 black Baptist church bombing in Birmingham, and a Republican who romanticises Alabama’s slavery era, calls Native Americans “reds” and Asians “yellows”, and who was accused by multiple women of inappropriate behaviour up to sexual harassment and assault, in several cases when they were underage. (He has denied their allegations.)

Mr Moore was an outrageous candidate from a defiant and angry political tradition that has been energised by Donald Trump. His defeat feels like an act of sweet justice – because it is. It is in part a win for #MeToo and will have consequences for that movement. He lost largely because Alabama’s African Americans rallied in heroic numbers to support Mr Jones and because a slice of the Republican electorate balked at him (including many white women – though 63% of those who voted still backed him, while 98% of black women supported Mr Jones).

The more complex judgment is about the extent to which the result was a rejection of Mr Trump as much as of Mr Moore. Mr Trump carried Alabama in 2016 by a 28-point margin. Mr Moore lost it by 1.5 points, giving the Senate seat to a Democrat for the first time in more than a quarter of a century. Much of this turnaround was Mr Moore’s own doing. Even the reactionary senior Republican senator for Alabama, Richard Shelby, recoiled; Mr Shelby’s preference for a write-in candidate may have been the killer blow.

Mr Trump’s role in the campaign was a powerful one, but it was tangled up in the ongoing battle within the Republican party. The president regretted his initial endorsement of another Alabama Republican, Luther Strange, who had been appointed to fill the seat in February and was supported by the Republican Senate leadership for this contest. While some Republican senators continued to refuse to endorse Mr Moore, Mr Trump defended him against his accusers, dismissed the abuse charges as a conspiracy, vilified Mr Jones, and campaigned loudly in neighbouring Florida days before the vote. The Moore campaign was driven in large part by the former White House adviser Steve Bannon, whose crude tactics replicated those he employed in the Trump campaign.

Many Senate Republicans will feel vindicated by the loss. Nevertheless they will all feel a cold wind as they contemplate their re-election prospects. The Alabama result is in line with the off-year results last month in Virginia and New Jersey, in which the suburbs also turned against Trump-backed candidates. Yet the congressional Republicans in the Senate and the House in Washington are not moderates. They differ with Mr Trump on several issues, but remain trapped by their obsessions with cutting public spending and taxes, and their fear of the party’s radical base.

In America, all politics is famously local. Alabama’s past hangs heavily over everything that happens there. Its deep past – slavery, race discrimination, militant resistance to the civil rights movement in the 1950s and 60s, the neglect of education for the poor – shapes politics in ways that were reflected on Tuesday. The near past matters too – and it is unusually turbulent. In less than two years, the Republican heads of all three parts of Alabama’s government have had to resign: the governor, who pleaded guilty to two misdemeanour campaign violations that arose during the investigation of an alleged affair with an aide; the state speaker over charges he used his office to advance his business interests; and the chief justice, Mr Moore, for refusing to carry out the law on same-sex marriage (he had been fired before, for refusing to dismantle a monument to the Ten Commandments that he had erected in his courthouse).

Wanting Trumpism to be in eclipse does not make it so. The forces that carried Mr Trump to the White House in 2016 are still there. The Democrats have internal conflicts of their own. Yet if a Trump-like Republican can be beaten in Alabama, then Trumpism can lose almost everywhere. Democratic hopes of winning back the Senate and perhaps the House in the 2018 midterm elections have received a huge boost, not least because the Republicans seem so incapable of responding effectively to the internal warfare that is destroying their party.