NBC News' Kristen Welker, Kasie Hunt, Monica Alba, and Danny Freeman contributed reporting.
There’s no such thing as a sure bet in politics, but Michigan certainly seemed like one for Hillary Clinton. The Real Clear Politics average of recent polls had her up by more than 21 points on Election Day, and the data whizzes at FiveThirtyEight gave her a 99 percent chance of winning the race. (After Sanders won, they also called it "one of the greatest upsets in modern political history.")
Even the Sanders campaign was bracing for defeat, and spent Tuesday pre-spinning a loss while the Clinton campaign gained little traction arguing the race was closer than expected.
RELATED: Michigan win rescues Bernie Sanders’ campaign
When exhausted Sanders staffers reached their hotel in Miami Tuesday night, they were stunned to find their candidate ahead in early returns and scrambled to assemble a podium so he could address the press. As Clinton gave a speech in Cleveland that did not mention Michigan, seemingly frustrated aides focused on Clinton's large net delegate win in Mississippi, which held a primary on the same day.
So what happened? Both campaigns are still picking over the wreckage for clues, but here’s what we know so far about how Sanders net an unexpected victory.
Sanders went all in, Clinton took her eye off the ball: Clinton seemed to take Michigan for granted after a string of big wins, leading her to begin turning to the general election. Team Sanders, meanwhile, saw Michigan as a must-win and invested accordingly. They outspent Clinton by about $500,000 on TV and spent almost three times as much on radio ads in the final week of the campaign as they had during any week in any state up to now.
Do the Michigan results change Ohio polls?March 9, 201603:23
Sanders brass deployed two veteran operatives — Robert Becker, who ran Sanders’ campaign in Iowa, and Julia Barnes, who ran his New Hampshire campaign — to help organize the state, and built a robust ground operation.
Clinton invested less heavily in her field program, which largely focused on African-Americans. Some supporters worried when they saw few Clinton yard signs, and some volunteers grumbled about disorganization and under-resourcing, but the realization of a major problem didn't come soon enough.
In closing days, the campaign scrambled to bring in reinforcements. They redirected Bill and Chelsea Clinton to spend more time in the state, and called on Michigan allies to rally troops. But it was too little, too late.
On a conference call with reporters Wednesday, Clinton's campaign manager Robby Mook pushed back on that notion. “We’re proud of the ground game we ran,” he said.
Geography: Clinton spent virtually all of her time in Detroit, along with a church visit in Flint last month and a small visit to a software company in Grand Rapids. Bill and Chelsea Clinton hit other parts of the state in the final push, but the candidate herself didn't hold any public rallies outside of Detroit during the entire campaign.
RELATED: ‘Ghetto’ gaffe highlights Sanders campaign’s struggle with race
While Clinton focused on population centers, Sanders allies said the candidate and his team did a better job of activating voters across the state. He won 73 of Michigan's 83 counties (though Clinton won the most populous ones), and ran up large margins in counties that include Grand Rapids and Ann Arbor.
Despite making Flint the soul of her Michigan campaign, Clinton didn't hold a single open event in the city during her five days in the state leading up to Tuesday. She also did not attend the watch party her campaign organized after Sunday’s debate in Flint, as she has in other states, disappointing some attendees.
Inroads with African-American voters: African-Americans have been determinative of the Democratic primary so far, and may have been in Michigan, too. Clinton was once again banking on black voters, but Sanders performed better with that group in Michigan than he did in the South. He still lost black votes 68 to 38, but that’s 20 points better than he did with that voting bloc in Mississippi. They also made up a slightly smaller proportion of the vote than expected.
Sanders’ core supporters turned out big: Young people, Sanders’ most important voting bloc, turned out in larger-than-expected numbers, with those younger than 30 making up the same portion of the electorate as those older than 65. Sanders visited every college town in the state, turning out huge crowds when he did, which the campaign says proves their point that they can move the needle anywhere they move their candidate.
Michigan's open primary allows independents to vote in either party, and Sanders always does well among among independents. He performed even better than expected with that group on Tuesday, winning 71 percent of independents casting ballots in the Democratic primary.
Some speculate that Clinton supporters were complacent and stayed home, or possibly even voted in the Republican primary in an attempt to stop Trump.
The weather: It was an unseasonably warm 70 degrees in much of the state on Election Day, helping to push up turnout in both party’s primaries to record levels. More than 2.5 million voters participated in the Republican and Democratic primaries, shattering the record of 1.93 million set in the 1972 primary and the expected 2 million turnout.
Fertile ground for Sanders’ message: Late-deciders broke for Sanders and most pollsters had stopped contacting voters on Sunday. Michigan was a perfect place for Sanders’ message because of its Rust Belt history and relatively friendly demographics. His emphasis on unpopular free trade deals and his performance in Sunday night's debate, while panned by some analysts, could have changed minds.
The Sanders campaign also believes Clinton’s charge (which they called misleading and unfair) that he voted against the auto bailout backfired. The auto rescue was included in the Wall Street bailout bill, which Sanders voted against, and they believe hitting on him on the issue played into the idea that she is dishonest and reminded voters of Wall Street. Mook rejected that claim outright. "We'll continue to talk about it,” he said.