On Tuesday evening, Republicans managed to perform a seemingly impossible task. They took a state that has been one of their most reliable bastions, a state that had elected Republicans to the U.S. Senate without fail for decades, and coughed it up to the Democrats. The Alabama seat that Doug Jones won in the special election had been held by now-Attorney General Jeff Sessions since 1997. He had won his latest term in 2014 without Democrats bothering to field a challenger. The other Republican senator from Alabama, Richard Shelby, won re-election last year with 63.9 percent of the vote against Democrat Ron Crumpton.

The stunning special-election loss will no doubt spark a heated debate over who gets the blame for the debacle. That starts with the choice of Republicans' nominee, but goes beyond that to a perhaps dangerous conclusion from the results of the 2016 election: that character no longer mattered in politics.

Initially, interim appointee Luther Strange appeared set to win the nomination and cruise to a special election victory. Republicans in Washington backed Strange, who faced challenges from Rep. Mo Brooks and former state Supreme Court Justice Roy Moore. Trump endorsed Strange, who had supported the president's agenda diligently from the time he first arrived in the Senate.

However, Moore campaigned as the more Trump-friendly candidate, and former Trump adviser Stephen Bannon fought hard for the colorful populist. Strange came under attack as a lackey of Senate Majority Leader Mitch McConnell even while carrying Trump's endorsement. Moore and Bannon transformed the primary into a populist fight, rallying the Make America Great Again throngs enough to carry Moore to a relatively easy win over Strange.

In a general election, however, Moore's message — and his past — came back to bite Republicans. Several women credibly accused him of sexual misconduct when he was in his 30s, including one woman who said Moore molested her when she was 14 years old. Moore disputed the mounting allegations with seemingly inconsistent responses, and tried to turn it into a war with the media.

Moore's track record on issues like criminalizing homosexuality, and his dismissive remarks on discrimination, also came back to embarrass Republicans. The day of the election, a spokesman tried to defend Moore's declaration that Muslims could not serve in Congress in an interview with CNN's Jake Tapper by saying that they could not swear on the Bible. When Tapper explained that the law does not require a Bible to be used — other religious texts can suffice, or no text at all — the spokesperson was struck mute. Moore's wife declared the night before that her husband couldn't be anti-Semitic because "our lawyer is a Jew." And earlier, the candidate himself told The Guardian that America might be more evil than Russia because of same-sex marriage.

The long string of incompetencies resulted in a stunning loss in which many Republican voters stayed home or wrote in a candidate while Democrats turned out for Jones in droves. Trump won Alabama by almost 600,000 votes a year ago, beating Hillary Clinton by 28 points. On Tuesday, Jones beat Moore by about 20,000 votes — good for a 1.4 percent margin of victory. The shift from last year's presidential and senatorial races in Alabama shows just how badly Republicans botched this race.

What can be learned from this debacle? First and foremost, to paraphrase Mark Twain: The reports of the death of character in politics was greatly exaggerated. Trump's win over Clinton last year supposedly demonstrated that a fighting spirit trumps character, so to speak, but that arguably misreads what took place in the 2016 cycle. Both candidates had character issues, which tended to cancel each other out, not lessen their importance overall. When a candidate with serious character issues runs against another without that kind of baggage, it's going to make a big difference — even bigger, in this case, than Jones' liberal pro-choice position on abortion. That is a lesson Democrats should take for the 2020 presidential race, and one which Republicans had better consider, too.

Populism still matters, but the focus of that populism matters more. Trump hit the familiar culture-war tropes in his campaign but focused most intently on economic populism. He bonded with working-class Americans on trade protection, immigration crackdowns, and job creation. Strange and Brooks could have done the same in Alabama, but Moore seemed much more focused on culture-war signaling, which clearly didn't excite the Republican base to turn out enough to rescue Moore from the voters he was alienating. Having campaign surrogates go on television to explain why homosexuality should be made illegal and why pregnant news anchors should fear Jones' thirst for abortions doesn't work in 2017, at least not in general elections. Not even, it seems, in Alabama.

Finally, the election proves that running against the "establishment" isn't necessarily going to capture the imagination of voters, especially when it comes to fighting on the basis of personalities. Voters want to know how candidates will improve their lives, not how they'll fight Mitch McConnell. While social media platforms amplify this kind of partisan and internecine sniping, most voters don't obsess over politics enough to care. They want government that works well where it should and stays out of everything else. Even Trump's talk about the "swamp" was framed to argue that he alone could drain it and deliver on the life-improving economic promises he made on the campaign trail.

Moore's loss might provide the GOP a silver lining. Had he been even a little more competent, Moore might have managed to eke out a win, leaving this seat vulnerable again in 2020 — and burdening Senate Republicans and President Trump with trying to explain their cynical backing of Moore every day between now and then. This loss is temporary anyway. Republicans won a Senate seat in deep-blue Massachusetts in a 2009 special election thanks to a combination of grassroots enthusiasm and an incompetent Democratic candidate, but Scott Brown couldn't hold it in the following election. Jones is almost certain to face the same fate if Republicans manage to find an even marginally more competent candidate in a general election cycle; Moore's loss will mean that an incumbent won't disincentivize talented candidates from jumping into a primary.

Most of all, it provides the GOP a wake-up call on character and focus. That lesson needs to sink in, not just in Alabama but across the country.