El Nuevo Herald via Getty Images Democratic presidential candidate Sen. Bernie Sanders (I-Vt.) speaks during a campaign event in Miami at the James L. Knight Center on Tuesday.

After a run of relative successes, polls missed in a big way Tuesday in Michigan's Democratic primary.

Surveys showed Hillary Clinton a heavy favorite in the state, with those conducted in March giving her margins of between 11 and 37 points over Sanders. HuffPost Pollster, which includes all publicly available polling, gave Clinton an 18-point lead.

Instead, Sanders pulled off a narrow victory, marking what could be a historic polling misfire.

In the famous New Hampshire upset in '08, Clinton trailed Obama by 8 points. Big upset. But today, Sanders trailed Clinton by *21* and won. — Nate Silver (@NateSilver538) March 9, 2016

What happened? It's too early to know for sure, but there are a number of things that could have gone wrong.

For one thing, though surveys in the state were consistent, they were relatively scarce. Fewer than 10 were released in the week before the election, with none fielded entirely after the Democratic debate Sunday in Flint, Michigan. Polling misfires often come down to a late surge toward one candidate, and Sanders made a concerted effort to swing the state. He outspent Clinton on ads in Michigan, according to data from Kantar Media, spending $3.5 million to her $2.6 million, and making a heavier investment in the last week before the primary.

Surveys show Sanders gaining steam in Michigan, rising an average 9 points since mid-February, and a CBS/YouGov survey found voters more likely to report rising opinions of him than of Clinton.

Exit polling also offers some hint of momentum for Sanders. According to preliminary results, he led by 7 points among the small fraction of voters who made up their minds last week, but trailed by 3 points among voters who decided prior to then.

A last-minute shift, though, likely isn't enough to explain the discrepancy, especially since pre-election surveys showed Sanders far more than 3 points behind.

The other possibilities largely revolve around demographics: Either Sanders turned out groups that favored him in heavier numbers than expected, or he managed to do far better among some groups than the polls anticipated.

Sanders himself predicted an upset, telling supporters last week that with high enough turnout, he could win. The state saw a record number of voters.

ALERT: Michigan has surpassed @MichSOS's 2 million voter turnout projection in both primaries with 85% of precincts reporting statewide. — Chad Livengood (@ChadLivengood) March 9, 2016

Results suggest that Sanders, who struggled to make any inroads among black voters in the South, fared significantly better in Michigan. Exit polls show him winning 30 percent of the state's black vote, compared with just 10 percent in Mississippi.

A NBC/Wall Street Journal/Marist poll of the state, which gave Clinton a 17-point lead, found him winning just 21 percent of African Americans, while a CBS/YouGov poll found Sanders taking just 19 percent of the black vote.

The pre-election polls also appear to have underestimated turnout among young voters, who overwhelmingly support Sanders. That same NBC/Wall Street Journal/Marist poll showed 18- to 29-year-olds making up 15 percent of the electorate, whereas the exit poll showed 20 percent of the electorate in that age group. In the pre-election poll, Sanders won the age group 74 percent to 25 percent; in the exit poll, his margin was bigger -- 81 percent to 18 percent.

There were also differences on education in the Michigan electorate compared to the polled electorate. The NBC/WSJ/Marist poll had 38 percent college graduates in its sample, while the exit polls show 45 percent of the electorate was college graduates. Sanders does notably better among college graduates.

Monmouth University pollster Patrick Murray, whose survey found Clinton 13 points ahead, attributed the miss to "voter volatility" rather than an error in sampling. He noted that their poll showed an older, more heavily female electorate than the results suggested by exit polls. Clinton also under-performed among moderate, conservative and African-American voters, he said, although none of those differences was enough to explain the magnitude of the miss.

"[T]he biggest difference seems to be among white voters and gender," he said in an email. "We had 49/48 Clinton among white voters compared to 42/57 in the exit polls. We had women at 59/36 versus 53/46 exit poll. We had men at 48/49 versus 44/54. So, it's a little bit of everything."

There are a few other possible factors at work. For one: Clinton voters, assuming she was a lock to win, might have felt less urgency to vote. Some, exit polls suggest, even might have crossed over to the Republican primary instead to vote against Trump.

I just keep meeting Dems in MI who say Hillary has the primary locked, so they cast anti-Trump votes for Kasich. — daveweigel (@daveweigel) March 8, 2016

Pollster Bernie Porn of the Michigan firm EPIC-MRA, whose final survey showed Clinton 25 points ahead, pointed to a broad combination of those factors, including unusually high youth turnout and a last-minute focus on U.S. trade policy.

"Based on past primary elections and what we expected as a reasonable increase for Sanders, we had about 12 percent age 18-34," he told HuffPost in an email. "We are guessing that the percentage age 18-34 was in the 18-20 percent range. When we reweighted our poll for a 20 percent level of turnout for age 18-34, we were within 3 points of where Clinton ended up as a percentage."

Porn added that Sanders' attacks on Clinton's trade record during and after the last debate likely had an impact that came too late for the polls to measure. And he noted that the Clinton-friendly areas near Detroit, unlike the rest of the state, saw lower-than-anticipated turnout.

As FiveThirtyEight's Nate Silver noted, Michigan has a long history of polling upsets. Add another one to that list.

This article has been updated with comments from pollster Bernie Porn.