AUGUSTA — A review of ballots from Long Island revealed Tuesday that a simple counting error caused a discrepancy in the state Senate District 25 election results, ending weeks of intrigue and swirling speculation about ballot stuffing and election fraud.

The discovery of the mistake – the double counting of 21 ballots during a Nov. 18 recount – effectively flipped the winner of the contest between Democrat Cathy Breen and Republican Cathy Manchester for a second time. Breen was the unofficial winner on Election Day, but the unexplained appearance during the recount of 21 “phantom ballots” from the tiny community of Long Island appeared to turn the contest for Manchester.

Now, with the mistake revealed and election officials on Long Island vindicated, Breen is expected to be seated when the Republican-controlled Senate reconvenes in January.

“Every step of this has been surprising to me,” Breen said. “So this goes along with a path of surprises.”

The revelation came during a jam-packed hearing Tuesday held by a special Senate committee at the State House. The committee’s highly anticipated review of the Long Island ballots followed weeks of widespread theories and rumors about ballot irregularities.

The possible discovery of wrongdoing loomed. Photographers snapped pictures of the locked ballot containers as they were brought into the hearing room by the Maine State Police. Nearly 30 witnesses had been called to testify, including all of the election officials from Long Island who had been pulled into the controversy.

Then, after nearly five hours of testimony during which Deputy Secretary of State Julie Flynn outlined in painstaking detail the chain of custody for election ballots, the mystery was solved. Sen. Roger Katz, R-Augusta, the chairman of the committee, asked Flynn and a state trooper wearing rubber gloves to open the ballot container to compare the recount tally sheets with the number of ballots, which were divided into four separate bundles.

One of the bundles had 21 fewer ballots than it should have. The other had 21 more – all marked for Manchester.

Flynn, who said she had overseen hundreds of recounts in more than 25 years, was stunned.

“I surmise the 21 votes for Manchester were counted, and got counted again,” Flynn said. She said it was likely that the 21 ballots mistakenly had been put into another bundle of ballots after having already been counted in the first bundle. That would have happened during the recount, conducted by two political party-appointed counters and overseen by an official from the Secretary of State’s Office – all three of whom were there to verify the count and certify the results.

“I believe (the error) happened in the recount, and I’m chagrined to say so,” Flynn said. “I’d eat my hat, if I had one.”

The discovery rippled through the hearing room. Manchester, seated in the front row for most of the morning, quickly departed, but later returned to say she had resigned her seat. She thanked the panel and said she was glad that the state police – which maintained custody of the ballots – and Long Island officials were exonerated of any claims of foul play.

“I have full confidence that no one did anything wrong, that we have human error at the recount,” she said. “I believe the people of District 25 have spoken, and they have spoken to vote Catherine Breen as their state senator.”

In addition to Long Island, the District 25 seat represents Falmouth, Cumberland, Yarmouth, Gray, Chebeague Island and part of Westbrook.

On election night, Breen was the apparent winner, 10,930 to 10,898. After the recount, Manchester led 10,927 to 10,916. The final recount total included ballots from other towns that had been missing and changes in vote totals for some towns.

Breen challenged the results of the recount, prompting the Secretary of State’s Office to refer the outcome of the election to the special Senate committee, which was appointed by Senate President Mike Thibodeau, a Republican.

Democratic officials and lawmakers, who had urged an exhaustive review of the recount, were giddy Tuesday, vindicated by the outcome. “Mainers got the answers they deserve,” said Democratic Party Chairman Phil Bartlett. He criticized Republicans, and Thibodeau in particular, for dismissing early calls for a review of the ballots and moving to provisionally seat Manchester last week.

The full Senate now will have to vote in January to seat Breen.

Thibodeau, his caucus decreased by one member but still in possession of the majority, declined to comment immediately after the announcement. He implied that his thoughts might not be suitable for publication, saying, “You can’t read my word balloon, man.”

Last month, before he appointed the special committee, Thibodeau said he hadn’t seen any evidence of ballot irregularities.

Later Tuesday, Thibodeau issued a prepared statement calling for a review of how such a mistake could have occurred.

“The candidates and the people of Senate District 25 – Long Island, especially – were put through weeks of uncertainty and media scrutiny following the recount,” he said.

Meanwhile, Brenda Singo, the Long Island town clerk, also was feeling vindicated. She and several election clerks oversaw the Nov. 4 election and kept a list showing that only 171 voters entered the polls on Election Day. When the recount turned up 192 ballots, the scrutiny swiveled to Singo and Long Island’s 238 registered voters.

On Tuesday, Singo addressed a phalanx of television cameras and said she’d always been confident that she and her team had gotten the count correct.

“I’m a by-the-book type of person,” she said.

Anne Donovan, one of the other Election Day clerks, had a different reaction.

“Someone owes my town an apology,” she said.