BOSTON - It was just after 10 p.m. and the Democratic primary in Massachusetts remained up in the air as Mayor Marty Walsh took the stage at a bar in the city's Seaport District, the screens showing CNN.

"I keep watching that TV because I want that yellow checkmark next to our name in Massachusetts," Walsh said. "But I can tell you when that happens it's because of Boston. We won by 20,000 votes today."

After a string of losses at the state level and in a local House race, Walsh's team was able to claim a win, even before the race was called.

Walsh had backed Clinton and sent his troops up to New Hampshire, though U.S. Sen. Bernie Sanders received 60.4 percent to Clinton's 38 percent.

Things were different this time: According to a preliminary tally from the Boston Elections Department, Clinton received 57.39 percent to Sanders' 41.40 percent.

In 2008, Clinton had won the Democratic primary in Massachusetts, but lost the city of Boston, despite the backing of Mayor Thomas Menino at the time.

Walsh had appeared earlier in the day with former President Bill Clinton in West Roxbury and the day before with Hillary Clinton in Boston's Downtown Crossing neighborhood.

Somewhat mirroring statewide results on the GOP side, Donald Trump also won Boston, according to the preliminary tally.

The businessman picked up 40.56 percent of the vote.

U.S. Sen. Marco Rubio finished second, with 24.02 percent of the vote, and Ohio Gov. John Kasich came in third with 22.68 percent. That was a reversal of the statewide tally, which had Kasich in second and Rubio in third place.

In Boston, U.S. Sen. Ted Cruz came in fourth place with 7.85 percent, and Ben Carson came in fifth with 1.87 percent of the vote.