In about the middle of January, Sen. Bernie Sanders (I-Vt.) suddenly separated himself from the other contenders for the Democratic presidential nomination in polling of the New Hampshire primary. Sanders had won the state four years ago, walloping Hillary Clinton. With only a few weeks to go, he seemed poised for a repeat victory, if not a repeat margin.

In numerous polls, though, voters indicated their minds weren’t entirely made up. Sanders and former vice president Joe Biden had national bases of support that appeared to be more immune to tepid support, but coming into the Iowa caucuses last week, it was clear that things could shift a lot.

After Iowa, they did. Former South Bend, Ind., mayor Pete Buttigieg tied Sanders in Iowa and surged in the polls. Biden, who did badly in the caucuses, suddenly dropped. Then another inflection point arrived Friday, with the last debate before the New Hampshire primary. Sen. Amy Klobuchar (D-Minn.) surged in the RealClearPolitics average of polls, joining Biden and Sen. Elizabeth Warren (D-Mass.) in a tight third-place cluster.

A tracking poll conducted by Suffolk University for the Boston Globe showed the recent shifts in support more clearly. A big gain by Buttigieg after Iowa (or, more accurately, after the Iowa Democratic Party released partial results of the caucuses). Then the debate, and a surge for Klobuchar.

Those lines, though, hide the uncertainty in the polling. If we add in shading representing the margin of sampling error, you see how messy things actually get. Sanders and Buttigieg have overlap, as do Klobuchar and Buttigieg. Sanders led, but not by enough to separate himself from the pack.

That appears to be what happened. Sanders edged out Buttigieg and beat Klobuchar more decisively. But he didn’t outperform where he was in the RealClearPolitics average by much, earning a bit less than was expected while Buttigieg overperformed slightly and Klobuchar substantially.

Preliminary exit polling from Edison Media Research tells a big part of that story. About half the electorate in the New Hampshire Democratic primary made up their minds about whom they planned to support more than a few days ago. They largely supported Sanders, making up about 7-out-of-10 votes he received.

The other half of the electorate decided in the past few days. About a fifth of voters said they decided whom to vote for only on the day of the primary. Buttigieg won both those groups, although Klobuchar essentially matched him among those who had decided in the days before the vote. More than half of Buttigieg’s support came from late deciders — as did three-quarters of Klobuchar’s.

Polls conducted a week ago wouldn’t have captured that late decision-making, helping to explain why both Buttigieg and Klobuchar beat the poll average.

Those last-minute choices muddied the campaigns in other ways, too. When I was in New Hampshire two weekends ago, Klobuchar didn’t have any apparent volunteer effort working on her behalf. As political veteran Addisu Demissie pointed out on Twitter, a lack of support over most of the campaign would leave volunteers without much to do, since voter-turnout efforts depend on having supporters to turn out. After the debate, it seems, Klobuchar suddenly got a bunch of people who chose to give her their support without the campaign having to do much at all.

But without last-minute deciders, Sanders probably wouldn’t have won. He beat Buttigieg by less than two points (as of writing), which is probably about what he picked up from those deciding on how to vote the day of the primary. About 1-in-10 Sanders voters probably decided to vote for him Tuesday.

Elections are usually fairly easy to predict. Candidates hold leads for weeks on end and go on to victory. That’s not what happened in New Hampshire. There, a race that had been the focus of attention for months was probably only determined in the last 12 hours before polls closed.