From left, Democratic presidential candidates Sen. Bernie Sanders, I-Vt., and former Vice President Joe Biden participate in a Democratic presidential primary debate at the Gaillard Center, Tuesday, Feb. 25, 2020, in Charleston, S.C., co-hosted by CBS News and the Congressional Black Caucus Institute. Credit: Patrick Semansky / AP

AUGUSTA, Maine — Former Vice President Joe Biden won towns big and small in his surprise victory in Maine’s presidential primary on Tuesday, though Vermont Sen. Bernie Sanders won Portland and along the coast in a few of the state’s other liberal strongholds.

Biden carried 10 of the state’s 16 counties in Tuesday’s election to win 34.3 percent of votes to Sanders’ 32.9 percent. The winner’s best performance was in Aroostook County, where he racked up two-and-a-half times as many votes as Sanders. In areas where Sanders still came away with the most votes, Biden was largely able to make himself a close second.

The Vermont senator performed best in Waldo County, where he led Biden by less than 500 votes. The two candidates also split college towns, with Sanders racking up large margins in Orono and Waterville. Biden came away with narrower victories in Lewiston and Brunswick.

The result was a far cry from Maine’s 2016 Democratic caucuses, when Sanders won 64 percent of votes over Hillary Clinton, coming away with the most votes in every county. Biden’s victory on Tuesday came especially as a surprise as he did not campaign in Maine, never ran ads here and received only a few endorsements.

In a Colby College survey conducted in mid-February, he finished in fourth place with just 12 percent of the vote, trailing Sanders, former Mayor Pete Buttigieg of South Bend, Indiana, and former New York City Mayor Mike Bloomberg.

But the former vice president surged in a chaotic few days leading up to the primary, when three candidates — Buttigieg, Minnesota Sen. Amy Klobuchar and billionaire activist Tom Steyer — dropped out of the race, with the former two endorsing Biden. Bloomberg dropped out of the race on Wednesday after performing badly on Super Tuesday and also endorsed Biden.