BOSTON (AP) — After nearly a quarter-century as the state's top elections official, Secretary of State William Galvin is facing his toughest re-election campaign in decades as he tries to fend off fellow Democrat and Boston City Councilor Josh Zakim in the Sept. 4 primary.

The contest heated up after the 34-year-old Zakim won the endorsement of activists gathered at the Massachusetts Democratic Party convention in June, beating the 67-year-old incumbent, first elected to the office in 1994.

The race has been caustic at times as the candidates scrabble for an office that has typically had a low profile.

That profile changed after the 2016 election, when reports of Russia's election meddling in the presidential contest thrust election security — and the state officials charged with overseeing elections — into a spotlight.

Zakim has tried to make election security one of his top issues in the primary fight.

In recent debates, Zakim faulted Galvin for not moving faster to harden protections against potential hacking and other threats to the upcoming elections.

"It's a head-in-your-sand approach to say just because we don't think anything happened in 2016 means we're OK for 2018 and 2020," Zakim said, during debate on WGBH-FM.

Galvin defended his efforts to protect voting from outside threats. The decision to keep the Massachusetts voting system off the internet has helped reduce the possibility of an attack, he said.

"We have not been hacked," he said. "We have a secure system."

Zakim has also faulted Galvin for being slow to embrace efforts to expand voting access in Massachusetts, like same-day registration, in part because he hasn't faced serious opposition.

Galvin said he has embraced changes meant to expand access to the ballot box.

He pointed to the state's decision to offer early voting for the first time in 2016. More than a million voters took advantage of the opportunity to case votes before Election Day.

Galvin said he also was part of the push for an automatic voter registration bill that was approved by lawmakers and signed into law by Gov. Charlie Baker this year.

The new system will automatically update a person's voter registration when that person notifies a state agency like the Registry of Motor Vehicles of a new address or other change in status. Galvin says the new system will begin automatically registering voters in January 2020.

The contest has turned scathing at times, with Galvin criticizing Zakim for failing to vote when he was younger and Zakim criticizing Galvin for anti-abortion votes he took decades ago as a state lawmaker.

Zakim has also criticized Galvin for scheduling this year's primary for Sept. 4, the Tuesday after Labor Day, when many people are just getting back to work after a holiday and may not be focused on the election.

Galvin said his hands were tied because he didn't want the primary to clash with Jewish holidays. Zakim said Galvin had other options, including setting the election for a weekend day.

One area where the two agree is the Electoral College.

Both said they would support efforts to amend the U.S. Constitution to eliminate the Electoral College — and both back a push to create a multi-state compact that would throw the needed electoral college votes to whichever candidates wins the popular vote.

Both candidates are also continuing to raise campaign funds at a good clip. As of mid-August, Galvin had about $411,000 left in his campaign account, compared with $437,000 for Zakim.

Zakim's name may ring a bell with voters in part because Boston's iconic Zakim Bridge is named after his father, Leonard "Lenny" Zakim, a local civil rights leader who was active in the city's black and Jewish communities.

Whoever wins the primary will face Republican Anthony Amore in the November election.