PITTSFIELD — Andrea Harrington has won her campaign to unseat Berkshire District Attorney Paul Caccaviello.

Harrington, a Richmond attorney, narrowly defeated Caccaviello, who was named to the post in March after the retirement of David F. Capeless, in Tuesday's primary. Great Barrington attorney Judith Knight was polling last in the three-way race.

Harrington was ahead by 551 votes with one town — Sheffield — yet to report results.

Caccaviello called his rival shortly after 11 p.m. to congratulate her on her victory.

Harrington, 43, who pledged during her campaign to reform the office, now will have the opportunity to put those words into action. She will become the first female district attorney in the history of Berkshire County.

"We did this together," Harrington said to a crowd of jubilant supporters as her victory seemed almost assured.

She now heads into the November election unchallenged, unless someone mounts a write-in campaign. When asked whether he'd run a write-in campaign, Caccaviello simply said it was "something to consider."

For about 75 Harrington supporters packed into Flavours of Malaysia in Pittsfield, the night was an emotional roller coaster. The mood fell when Caccaviello took Pittsfield early in the evening, but it picked up as Harrington filled the gap and eventually emerged victorious.

At one point, Mayor Linda Tyer took a call, leaning over her husband's computer as the two crunched numbers. Pittsfield city councilors poured through the door.

"This is going to be a long night, folks!" Council Vice President John Krol yelled, pumping his fist. "We're coming back with all the hilltowns coming in!"

Just after 9 p.m., calls came in reporting Andrea was up by 122 votes. Not long after, Harrington's headshot bumped out Caccaviello's on the television screen as Pittsfield Community Television's numbers reflected her lead.

"This is so exciting!" Julia Kaplan yelled, throwing her hands together.

Just before 10 p.m., Harrington walked into the restaurant to boisterous applause and chants of "An-dre-a. An-dre-a."

"People like us do not win. We fight for the underdog every day," she said. "But tonight it looks like we may have changed that story."

Numbers coming in show the county "has chosen hope over fear."

She knew it would be a hard road, she said, but it was even harder than she expected. "I'm trying to decide what's harder — natural childbirth or this race," she said, to laughs from the crowd.

The restaurant buzzed with excitement late into the evening.

Dennis Powell, president of the Berkshire branch of the NAACP, said he's hopeful that Harrington can make a difference in the Berkshires. "Change is needed in Berkshire County in the criminal justice system," he said.

And if she wins, he said, "justice is served."

Linda Kelley, an active resident of Pittsfield's West Side, said Harrington has what the county needs in its district attorney. "You can hire experience," she said. "What you cannot hire is vision."

Tom Sakshaug, who managed Mayor Linda Tyer's campaign and worked heavily on Harrington's, said progressive politics means taking a long-term view.

"If you want progressive things to happen, you have to give it some time," he said.

Caccaviello calm

A crowd of friends, family and supporters broke out into applause when Caccaviello entered a banquet hall at Mazzeo's Ristorante just after 9 p.m.

While Harrington had the public support of Pittsfield's progressive community leaders, city councilors Kevin Morandi and Melissa Mazzeo and Berkshire County Sheriff Thomas Bowler were among Caccaviello's endorsements.

Early in the night, some supporters expressed confidence that Caccaviello's experience and commitment to the job were enough to carry him through the contentious race. Others said they expected it to be tight, and were concerned that Caccaviello and Knight's caseload may have put them both at a disadvantage to Harrington.

"It's like having the jury out," Caccaviello said about his calm demeanor while he and Harrington battled for the lead.

Kristen Gordon, seated with her 73-year-old mother, said Caccaviello was their hero.

In 2008, he successfully prosecuted the woman who sold the fentanyl patch to her sister, Carlen Robinson, who was addicted to painkillers.

"Every day we saw the empathy, the wonderful man Paul is," she said, "and in the courtroom we saw the ferocious prosecutor he is."

"He helped me believe this really wasn't my sister's fault," Gordon said. "That's something I was struggling with."

Throughout the race, Caccaviello's opponents have painted him as a continuation of Capeless, who many labeled as overzealous in his prosecution of low-level crimes.

While Caccaviello has consistently stopped short of criticizing his predecessor, he ensured voters he would bring a "different approach" to the office's longstanding commitment to justice.

That approach will include the vertical prosecution of domestic violence cases, increased community outreach and a mission of "compassion when appropriate, but consequence when it's needed."

Caccaviello, 53, has worked as a prosecutor in that office for nearly 30 years and replaced Capeless when he retired in March. He had committed to be accessible as district attorney, increase community outreach, and reorganize how domestic violence cases are prosecuted.

He was appointed by the governor to replace David Capeless upon his retirement in March. He faced backlash after it was learned Capeless and the governor's office had exchanged emails about Caccaviello's possible appointment before he announced he was leaving the office.

Tensions were high throughout the uncommon three-way race for district attorney.

Statewide, the American Civil Liberties Union has run a campaign to educate voters on the role of the district attorney.

In the past 20 years, 77 percent of Massachusetts district attorney races have been uncontested, and this year, six districts have contested races, according to Rashaan Hall, a former Suffolk County prosecutor who headed the ACLU effort. Camps for each candidate became more spirited as the primary, which decided the race, approached.

Supporters praise Knight

Amid tacos and pitchers of margaritas at Tito's Mexican Grill in Pittsfield, Knight's supporters praised their candidate for her integrity and progressive agenda. As it became clearer that she wouldn't win, Knight told The Eagle that the campaign was a blessing in that it brought the workings of the DA's office under a bright light.

After Harrington jumped into the lead late in the evening, Knight said she wished her well.

She said she still wants to work toward more diversion programs, noting the community wants to see changes that include keeping low-level, nonviolent offenders from dragging through a torturous system.

Some of her supporters decried the political aspect of the race.

"I wish yard signs were outlawed," said Mary Hart. "They make people forget about the facts."

"Politics gets in the way of good work ... there's a lack of substance," said Karen Davis, speaking to what she said is Knight's integrity.

"She's not a politician — she's not polished like a politician — she speaks from the heart," said Jeanet Ingalls.

There were cheers when televised results announced that Knight had won Otis and Becket.

When asked if she would mount a write-in campaign for the November election, Knight said she hadn't thought about it — until now.

"No, the election is the election," Knight said. "I will just accept the results."

Eagle staff writers Haven Orecchio-Egresitz and Heather Bellow contributed to this report.

Amanda Drane can be contacted at adrane@berkshireegle.com, @amandadrane on Twitter, and 413-496-6296.