BOSTON (State House News Service) – Tens of thousands of registered voters in Barnstable will get an extra four hours to cast their ballots Tuesday night after an inaccessible vault upended the start of primary election day.

Suffolk Superior Court Judge Patrick Haggan ordered the town to keep its polls open until midnight, seeking to prevent “irreparable harm” to voters. The polls had been scheduled to close at 8 p.m.

The town will offer 13 voting hours, the same amount as the standard 7 a.m. to 8 p.m. schedule, for Barnstable residents who want to submit their picks in a major election featuring tight statewide races as well as contested Republican primaries for the U.S. House, state Senate and district attorney.

“My primary goal today is making certain that every voter in Barnstable who wants to vote is able to do so,” Secretary of State William Galvin, who filed a complaint seeking the longer hours, said in a statement. “Extending polling hours was necessary to make sure voters have enough time to be notified and return to their polling places if they weren’t able to vote this morning.”

Polls across Massachusetts opened at 7 a.m. on Tuesday, but in Barnstable, Town Clerk Ann Quirk was unable to open the vault where ballots are stored. Officials pivoted to printing emergency paper ballots, and by about 11 a.m., all 13 Barnstable precincts across 10 different locations were able to accept those forms of votes.

Quirk told reporters around 1 p.m. that there was no problem with the vault over the weekend during preparations for the election.

“When we went to open the door, it would not open,” Quirk said in a video posted by CBS Boston. “I don’t know what happened to the door overnight, but it broke is the best thing I can say. It broke.”

Paper ballots will need to be hand-counted, a process that cannot begin until Barnstable’s polls close at midnight.

Quirk said other town clerks on the Cape told her they are willing to assist with counting ballots Tuesday night once they finish in their own communities.

“The integrity of the election is always uppermost in our minds. As town clerks, that’s our job. That’s what we get paid to do,” Quirk said.

The vault was still closed Tuesday afternoon, and reporters on scene around 3 p.m. described locksmiths working — possibly using a drill — to get it open.

Galvin spokesperson Deb O’Malley said 4,019 ballots had already been cast in Barnstable during early voting or mail-in voting. Most of those ballots have been processed, but they cannot be added to totals until polls close.

The upheaval in Barnstable forecasts a longer night for election workers and candidates in the area. If any statewide races come down to a particularly tight margin, those could get impacted, too.

Barnstable, the largest municipality in Barnstable County, is home to 35,568 registered voters. Of those, 7,701 are Democrats, 4,799 are Republicans and 22,729 are not enrolled in either party, according to data from Galvin’s office.

In the 2018 state primary, 3,849 Barnstable voters cast ballots in the Democratic primary and 386 cast ballots in the Republican primary, according to records on the town clerk’s website.

Barnstable is split across two districts in the Massachusetts House. Democrat Rep. Kip Diggs is the only candidate on either ballot in the Second Barnstable District, as is Republican Rep. Steve Xiarhos in the Fifth Barnstable District.

Democrat Sen. Julian Cyr, who does not face a primary, also represents Barnstable. Two Republicans from Barnstable, Daralyn Heywood and Christopher Lauzond, are running to secure a spot against Cyr in the general election.

The town also features a contested Republican primary for the Ninth Congressional District, with Jesse Brown of Plymouth and Dan Sullivan of Plymouth facing off to determine who will challenge incumbent Congressman Bill Keating.

Three Republicans are in the running for the open Cape and Islands district attorney’s office, whose district includes Barnstable: Melissa Alden of Barnstable, John Carey of Sandwich and Daniel Higgins of Barnstable.

During the early afternoon press conference, Carey asked Quirk how the delay would affect him and other candidates on the ballot.

“I wish I could answer that,” Quirk replied. “I know that we’re going to count all the ballots. I don’t know whether people will come out after 8 o’clock. I can’t foresee that.”