Combine Donald Trump’s refrain that the election is rigged with evidence that political campaigns profoundly misperceive their odds, and you get a recipe for potential unrest. Research that we conducted during the 2012 election demonstrates that voters, campaign workers, and even candidates massively overestimate their odds of winning elections.

So while the current polling data may point to a narrow victory for Clinton, you can bet that right now, both of the campaigns and their supporters believe that they are going to win this thing. If they don’t, they’ll search for answers. A rigged election is the answer that Trump is selling.

It’s no secret that we all occasionally lie to ourselves about our chances. If we didn’t, we would quit when facing long odds. Sport seasons would end early, and many campaigns would fold well before Election Day. There would be fewer long-shot winners and improbable comebacks. This is a manifestation of a general phenomenon psychologists call motivated reasoning, where we decide to accept and reject facts to fit with attitudes that are important for us. In the campaign world, motivated reasoning will cause people to believe polls are skewed so that they can continue working when faced with likely defeat.

This tendency to believe we will win, even in the face of defeat, is common in the campaign world, even among sophisticated staffers, volunteers, candidates and supporters.

Here’s how we investigated this

Last election cycle, we conducted a unique survey of Democratic campaign workers. They included those working on local races all the way up to the campaign for president. We did this by embedding a survey tool into the Democratic Party’s voter-contact computer system. As workers were doing their campaigning, we interviewed them. We collected data from almost 3,500 campaign workers across 200 campaigns.

We asked a straightforward question: What percent of the vote share would their candidate (including President Obama) win in their district or state? We compared their answers with the actual vote share. We also asked a representative sample of everyday voters about their predictions for the presidential race in their states.

Even big losers are sure they’re going to win

A very clear pattern emerged: Almost nobody thinks they will lose — even those who eventually lost badly.

Seventy-four percent of Democratic campaign workers overestimated their candidates’ vote shares, 77 percent of those working for Obama overpredicted his eventual vote share in the states they were working in, and 72 percent of Democratic voters overpredicted how well Obama would do in their states.

Overconfidence is especially pronounced among the most liberal and conservative in the electorate. Perhaps those are the ones who most care that their candidates win — and, therefore, are the most motivated to ignore or distort information, such as polls, that tell them otherwise.

Down-ballot campaigns may have misperceived their odds in part because they lacked polling information. Indeed, we saw greater prediction errors in down-ballot races than in the presidential race.

But staffers and volunteers were way off in the 2012 presidential race, too, where they had ample polling information to guess reasonably correctly.

To maintain the sort of optimism that we saw requires considerable mental gymnastics. Many people will convince themselves of a reason the election is close — that the polls must be wrong or that things can change at the last minute — to justify voting when the result in their state will be a blowout.

Who was good at predicting the result?

Those who best assessed the odds in our data came from two groups.

First, independent voters were pretty accurate in their assessments of the presidential race in their states. They weren’t motivated to overpredict one side or the other.

Second, incumbent campaigns were much more accurate than challenger campaigns. Incumbents and their staff, who are anxious about losing their seats and jobs, seem to tell themselves that the race is close even when they are likely to win handily.

In 2012, contrary to nearly every poll, the Romney campaign “went into the evening confident we had a good path to victory.” After the loss, a senior adviser told CBS News, “I don’t think there was one person who saw this coming.” When campaigns lose, they are surprised about it, no matter what the pre-election polls have to say.

Like the Romney campaign and most other campaigns, the Trump campaign now thinks it will probably win. That isn’t new. What’s new, of course, is that the Trump campaign is preparing to claim that a loss is explained by election-rigging. It’s the combination of these phenomena that is worrisome.

Ryan D. Enos is associate professor of government at Harvard University. Find him on Twitter @RyanDEnos

Eitan Hersh is assistant professor of political science at Yale University and author of “Hacking the Electorate: How Campaigns Perceive Voters.” Find him on Twitter @eitanhersh