Former Vice President Joe Biden has won a shock victory in Maine, upsetting Sen. Bernie Sanders in the northern New England state.

Biden’s win in Maine Wednesday morning over the Vermont senator — who won 64 percent of the vote in the Maine primary in 2016 — was fueled by new momentum after an overwhelming victory this past Saturday in the South Carolina primary. He also overcame nearly $500,000 in estimated political ad spending in Maine by former New York City Mayor Mike Bloomberg in the final few weeks of the race, according to data provided by Kinetiq, a TV intelligence platform.

Of the handful of polls released leading up to the race, most showed Sanders with a significant lead over his competitors, especially drawing from the state’s more liberal areas around Portland and its southernmost county, York. But in the most recent polls, Biden had been gaining ground.

According to a Data for Progress poll conducted February 28-March 2 and released Tuesday morning, Sanders led his fellow candidates with 34 percent support, while Biden rode a late surge to 25 percent. Sen. Elizabeth Warren and Bloomberg followed with 20 percent and 18 percent respectively. All four polled above the state’s 15 percent viability threshold required to earn portions of Maine’s 32 delegates.

In an earlier poll conducted by Colby College poll February 10-13, Sanders garnered 25 percent support among likely voters, and former South Bend, Indiana, Mayor Pete Buttigieg, who has since dropped out of the race, was the only other candidate polling above the viability threshold, at 16 percent.

There was also an institutional change that could have helped boost Biden to his surprise win. Maine has gone back and forth between primaries and caucuses over the past several decades. In 2008, state officials changed to a caucus format, which Barack Obama won. However, the state (and 10 others) changed back to a primary format for this year’s contest.

“There will be a lot more folks who have the interest to vote in a primary but not spend a few hours at a caucus, and those folks are more likely to vote for some of the moderates,” said Dan Shea, a professor of government at Colby and lead researcher on their poll.

The state will likely see a bit more campaigning again this fall, as Maine splits its electoral votes between the statewide vote and votes in each of the state’s two districts — a twist that Donald Trump took advantage four years ago, winning the northern Second District.

So it’s likely that Biden, or whoever ends up as the Democratic nominee, will be coming back to Maine with at least some frequency this fall.