As citizens across the country watched the electoral map turn red the night of Nov. 8, a small town north of Boston turned unexpectedly blue.
Boxford, the only municipality in Greater Boston that had voted Republican in every presidential election since Richard M. Nixon’s 1972 campaign, went for Hillary Clinton over Donald Trump.
“I have no idea where it came from,” said Elaine Spiro, secretary of the Boxford Council on Aging. She said everyone she spoke to in town was shocked.
But Boxford was far from the only town in Greater Boston to switch party allegiances this presidential election. Twenty-five communities that had backed Republican Mitt Romney in 2012 voted for Clinton on Nov. 8. Only four towns in the region — Bellingham, Freetown, Salisbury, and Saugus — flipped in the other direction to support Trump.
While a Globe analysis of statewide election results showed a reddening of Massachusetts’ western counties, the cities and suburbs to the east turned a deeper shade of blue. Clinton was backed by 130 of about 160 Greater Boston communities, compared with 109 that voted for President Obama four years ago.
The towns that flipped from the Republican to Democratic column this year share two major characteristics: Their residents in general have high incomes and are highly educated. In each town, the median household income and the share of the population 25 years or older with a bachelor’s degree or higher is well above the statewide average.
The communities include a string of South Shore towns stretching from Hingham to Duxbury; affluent western suburbs like Dover, Medfield, and Norfolk; and small but wealthy towns north of Boston, such as Topsfield and Hamilton.
Michael Kryzanek, professor emeritus of political science at Bridgewater State University, said Clinton’s relative strength in those places may be explained by some voters’ distaste for Trump, coupled with the existence of liberal Republicans in the Charlie Baker mold.
“I think a number of those liberal Republicans in the coastal area would have no difficulty crossing party lines, because of their likely disgust of Donald Trump,” Kryzanek said.
Duxbury, where the median household income is over $120,000, saw a dramatic swing between 2012 and 2016. Romney defeated Obama there by more than 11 percentage points, but this year, Clinton beat Trump by more than 12 percentage points.
The town’s Republican committee endorsed Trump, and its chairman, David Uitti, said he did not personally know of any registered Republicans in Duxbury who voted for Clinton. But, he added, “I suspect there are some who either voted third party, or who followed the lead of the governor and didn’t vote for anyone for president.”
Uitti doesn’t see Clinton’s win in Duxbury as a sign that its residents’ political leanings have changed.
“I don’t see any kind of shift happening in Duxbury,” Uitti said, “or on the South Shore, which has traditionally been a pretty big Republican stronghold in Massachusetts. I think the function of how things occurred in this election are simply because of the candidate that was running.”
In affluent Hopkinton, where Romney won by a mere 128 votes in 2012, the contest this year wasn’t even close. Clinton won 60 percent of the vote, with Trump netting under a third.
Darlene Hayes, chairwoman of the town’s Democratic committee, chalked up part of Clinton’s strength to her committee’s robust effort to knock on doors and make phone calls.
“We even had Joe Kennedy come up,” Hayes said.
While she knew Republicans who crossed party lines to vote for Clinton, she doesn’t believe a political realignment is happening in Hopkinton. In fact, she said, the town’s Republicans and Democrats have a lot in common: The “fiscally conservative, socially liberal” label applies to both.
“There’s less people we’d refer to as ‘Birkenstock Democrats’ in Hopkinton,” she said. That has an effect on elections: “Normally, we’re very, very close,” Hayes said.
Despite Clinton’s strength in many of Boston’s most affluent suburbs, a cluster of reliably Republican towns south of the city — including Middleborough, Carver, and Halifax — backed Trump more strongly than they did Romney, according to an earlier Globe analysis.
Kryzanek says that area, where incomes and education levels are not quite as high as they are on the coast, has attracted many working-class families in recent decades.
“Housing is relatively cheaper here,” Kryzanek explained. “The highway system is such that people can get around; the train is here; the schools are not Weston or Wellesley, but they’re pretty good school systems.”
“These aren’t very diverse towns at all,” said Peter Ubertaccio, a political science professor at Stonehill College, “but there are going to be more blue-collar workers who have been more susceptible to change in the economy.”
Salisbury, tucked in the state’s northeastern corner, gave President Obama a win of almost eight percentage points in 2012. This year, Trump edged out Clinton by more than 3 points.
While Salisbury’s median household income is more than $8,000 higher than the statewide average, the share of the population with a college education is more than 10 percentage points lower than the statewide average.
“We’re working class up here,” said Marshall Maguire, chairman of the town’s Republican committee. “We have a lot of union people here.”
Like many communities in Massachusetts and across the country where Trump outperformed Romney, Salisbury is sparsely populated — about 8,500 people live there.
“Trump’s message is resonating in rural areas,” Ubertaccio said. “It may be that Mitt Romney just wasn’t able to speak to those folks four years ago.”
And in Boxford?
Mike Cosco, owner of West Village Provisions in town, attributes it to a sense of discontentment he thinks many Republicans across the country had been feeling since Trump’s nomination in July.
“It’s got to be that Trump isn’t a traditional Republican candidate,” he said. “I think a lot of people were voting against Trump and not for Clinton.”
Jacob Carozza can be reached at email@example.com. Follow him on Twitter @jacobcarozza. Vanessa Nason can be reached at firstname.lastname@example.org.