I’ve been covering American elections at FiveThirtyEight for almost 10 years. During that time, by far the most remarkable outcomes — of course — were Barack Obama being elected president in 2008 and Donald Trump being elected in 2016.

But in third and fourth place were two special elections to the U.S. Senate: Scott Brown’s January 2010 election in Massachusetts and Doug Jones’s victory on Tuesday night in Alabama. Each occurred at roughly the same point in Obama’s and Trump’s respective terms.

Brown didn’t last long in office — he was defeated by Elizabeth Warren in 2012 — so it would be easy to overlook his significance. But his win was a huge deal. Slightly more than a year after Obama had been elected in a 365-173 Electoral College landslide, Democrats had lost Ted Kennedy’s former seat in Massachusetts, a state Obama had won by 26 percentage points. Brown’s win threatened the passage of Obamacare — although Democrats ultimately passed it anyway — and presaged a massive wave in the 2010 midterms, in which Democrats lost 63 House seats.

Alabama has some of the same qualities as Massachusetts, just with the parties swapped. Trump won Alabama by 28 points last November, and that in some ways understates the difficulties Democrats face there because Alabama votes Republican for pretty much every office, regardless of the candidate. (Massachusetts, on the other hand, has fairly often elected Republican governors.) Furthermore, somewhat like with Massachusetts and Obamacare, the Alabama election represented a referendum on one of the most pressing political issues of the day: the increasing number of powerful men (including political candidates, men in Congress and President Trump) who have been accused of serial sexual harassment or assault. In Moore’s case, the accusations were especially egregious because they involved underaged girls.

After Massachusetts, I went through an exercise to assign blame for the outcome. The conclusion was that “when a Democrat loses a federal race in Massachusetts, the default assumption ought to be that several factors are to blame.” Some of the blame had to go to Democratic candidate Martha Coakley, who had blown a fairly large (although obviously not insurmountable) lead in the polls with a series of gaffes. Some of it had to go to other circumstances peculiar to Massachusetts, such as that the election had been a power grab, with Democrats having repeatedly changed the rules for how replacement senators were appointed in the state. But much of the problem also had to do with the national political environment. There were plenty of signs by early 2010 that it had shifted substantially toward Republicans.

We can go through a similar exercise in Alabama. By the way we usually calculate these things, Alabama is 28 or 29 percentage points more Republican than the country as a whole, but Jones just won an election there by 1 or 2 points, representing a 30-point swing from the norm. That is, we have about 30 percentage points worth of blame to assign. So how to divvy them up? Consider:

First, we can assign about 10 points to the national political environment . That’s because the generic congressional ballot favors Democrats by about 10 points, meaning that you’d expect the Democrat to win the typical swing seat by about 10 points in this political climate.

. That’s because the generic congressional ballot favors Democrats by about 10 points, meaning that you’d expect the Democrat to win the typical swing seat by about 10 points in this political climate. Next, we can assign about 10 points to Moore’s problems as a candidate other than the sexual misconduct allegations . If Republicans ordinarily win in Alabama by 25 or 30 points and the national environment favors Democrats by 10 points, you’d expect a “generic” Republican candidate to be ahead by 15 or 20 points. Instead, Moore’s lead was in the range of 5 to 10 points in polls before the sexual misconduct allegations came to light.

. If Republicans ordinarily win in Alabama by 25 or 30 points and the national environment favors Democrats by 10 points, you’d expect a “generic” Republican candidate to be ahead by 15 or 20 points. Instead, Moore’s lead was in the range of 5 to 10 points in polls before the sexual misconduct allegations came to light. And finally, we can assign another 10 points to shifts in voter preferences and turnout patterns because of the misconduct allegations. That roughly matches the swing from the pre-allegation polls to Jones’s eventual margin of victory. It also lines up with empirical research on the electoral effects of scandals. Although many voters didn’t believe the allegations, many others did, and it affected Moore’s campaign in a variety of ways, such as by decreasing Republican enthusiasm.

Unless all three of these factors had lined up perfectly for Jones, he would have lost — perhaps by a significant margin. For instance, if Trump were more popular and the Republican brand were in better shape, the GOP could have willed more of its voters to the polls and Trump’s last-minute endorsement of Moore might have been more effective. Instead, Trump’s approval rating was only 48 percent (against 48 percent disapproving) among special election participants in one of the country’s reddest states.

The question for Republicans is to what extent these factors will be replicated in other races in the 2018 midterms and in other special elections between now and then.

Obviously, the national environment is highly problematic for Republicans — and in all likelihood, it will continue to be problematic for them through next November. Republicans ignore signs of this at their peril, because they’ve now gotten poor results in Alabama, a host of other states, the generic ballot and Trump’s approval rating.

Of course, Republicans won’t have Roy Moore running in other races. But they will have other candidates with characteristics similar to Moore (ignoring, for now, the sexual misconduct allegations). That is, they’ll have candidates who are nominated by the GOP base against the wishes of party elites and who prove to be disasters with swing voters. There could be more of them in 2018, especially with Steve Bannon targeting “establishment” Republicans in almost every Senate race. Republicans have had plenty of these over past election cycles, such as Todd Akin and Richard Mourdock in 2012 and Sharron Angle, Christine O’Donnell and Ken Buck in 2010. If not for these candidates, Republicans might have somewhere in the neighborhood of 55 Senate seats instead of being down to 51.

Both Republicans and Democrats will have to deal with other candidates — perhaps dozens of them — who are credibly accused of sexual harassment or sexual assault. Polls suggest that voters care quite a lot about this misconduct — Al Franken’s approval ratings tanked in Minnesota after several allegations of groping and unwanted kissing, for example. Again, there’s risk here to both parties, but because Republicans occupy most of the swing seats in the House — and because a higher percentage of Republican members of Congress are men — they have somewhat more liability.

In all but a handful of the 239 Republican-held House seats, 26 Republican-held governorships and eight Republican-held Senate seats that are up for election next November, these factors will not line up for Democrats in quite as fortuitous a way as they did in Alabama. That’s a good thing for the GOP, because if Democrats won every House seat as red as Alabama, they’d gain something in the order of 160 House seats from Republicans next November.

But Democrats need 25 House seats, not 160, to take over the House next year. And they need two Senate seats — not eight — to win that chamber. (Jones’s win has substantially upped the odds of a Senate takeover; Democrats face an awful map but now have a clearer path to victory than they did 24 hours ago.) In the 2010 midterms, Republicans didn’t win a single House seat as blue as Massachusetts. They nonetheless picked up 63 seats and delivered a crippling blow to Obama’s agenda. Not every race is going to go as badly for Republicans as this Alabama Senate election — but if enough go half as badly, or even a third as badly, they’re still in for a rough time next year.