GADSDEN, Ala. — Five seconds before the polls closed, the crowd at Back Forty Brewing gathered around the TV and counted down.

“Five, four, three, two, one,” they shouted. When the “key race alert” flashed — “too early to call” — some of the five-dozen Democrats in the brewery let themselves cheer. Roy Moore, who had become Gadsden’s most famous former citizen, was locked in a close contest with their preferred candidate.

“I’m just so excited,” said Ann Green, the chairman of Etowah County’s Democratic Party. “But I’ve always been an optimistic person, and Roy Moore’s always been a bad candidate for Alabama.”

Alabama Democrats, pushed into irrelevance during Barack Obama’s presidency, spent 11 dizzying weeks in the national spotlight. Gadsden, one of the cities jokingly referred to as a “blue dot in a red sea,” had been bathed in a particularly harsh light — it was here, in the early 1980s, that Moore allegedly made unwanted advances on young girls.

On Tuesday night, as Democratic nominee Doug Jones marched toward a historic upset over Moore, Etowah County’s beleaguered Democrats watched in disbelief. They gritted their teeth as election results rolled in. For much of the night, as the raw vote showed Moore, the Republican nominee, leading Jones, they discussed the Senate race as a galvanizing learning experience.

“I really think it’s given us an opportunity to build the Democratic Party,” said Kyle Pearce, a candidate for state representative from Gadsden. “Doug Jones was able to build a field operation throughout Alabama.

There are people who have never knocked on doors before who have been through a campaign now. That was a gift that I frankly did not expect at the start of the year.”

Alabama, one of the country’s most socially conservative states, had never struck national Democrats as the place for an upset. Democrats in Etowah had watched the party’s major figures avoid Alabama; Obama appeared in the race with an Election Day robo-call, saying nothing about Jones’s fight against Moore until then.

“I think Barack Obama hurt the Democratic Party all over the South,” said Maitland Adams, 75, the former chair of the party in Etowah. He’d had the unwelcome task of electing Democrats during the height of the Obama backlash, and until Jones climbed into the lead Tuesday night, he was full of worry.

“The abortion issue hurt us,” Adams said. “People simply don’t understand the position of the Democratic Party on abortion.”

Supporters of Democratic Senate candidate Doug Jones celebrate in Birmingham, Ala., as Jones is declared the winner during his election night gathering Tuesday. (Getty Images)

Other Democrats began talking about why they’d come off the sidelines to become activists. Carl Peterson, 36, said he had never canvassed for any candidate until Jones secured the Democratic nomination, and Moore became the Republican nominee.

“I wanted this to be a huge step forward for my state,” Peterson said. “We’re living in a time when every vote feels like it matters, more than it did before.”

Peterson was nervous. Two hours after the polls had closed, things started looking up. Bill Browning, 70, stared intently at one of the brewery’s TVs, as Moore’s lead kept falling.

“One point! One point!” he shouted late into the evening, as a surge of ballots from Dallas County — a buckle of Alabama’s “black belt” — tightened the vote count.

Browning had marched in the 1965 Selma to Montgomery campaign for voting rights. After that, he decamped for New York. He’d returned in August, and begun exploring a campaign for the area’s deep red Republican seat in Congress.

“I told Chuck Schumer, months ago, in a letter, to take this race seriously,” Browning said. “People thought this couldn’t happen, and it’s happening.”

A few hours into the night, as Jones moved closer to victory, Etowah County’s Democrats began to get rowdy. The brewery had two TV screens — one on a tape delay, one live. A rumor rumbled around the bar — something about the Associated Press calling the race — and the crowd gathered around the real-time TV. The cheers began as soon as the CNN broadcast began playing its dramatic election-projection music.

“I’m going to cry!” said Kim Hood, 62, wiping her eyes with one hand and cradling a cocktail with the other. “This is Alabama! We never win anything — anything!”

The call, which made Jones the first Democrat to win a Senate seat in Alabama since 1992, turned the party into an emotional rave. Several women who said they had been personal friends of Moore’s accusers wept and hugged their fellow voters. Anthony Wilson, 62, found his son — brewery co-owner Jason Wilson — and gave him a high-five.

“I could not be more proud of my state,” Anthony Wilson said. “We showed the world what Alabama really is.”

Jason Wilson composed himself, and talked about an Alabama that could show its face to the rest of the country — something he had been worried about had Moore won.

“There’s just a wonderful group of progressive thinkers in Alabama who don’t get their due,” he said. “My joke for years has been, I want to make a T-shirt: Hey, America, Give Us 10 Years. You know — we’re gonna figure it out. Just give us time. We get such a bad rap, and tonight we draw a line and told people what we really stand for.”

The brewery was supposed to close hours earlier, but revelers kept it open long into the night. Jerry Vaughn, 35, settled his tab while admitting that Alabama had dodged a blow to its national reputation.

“You know, I’ve got a 7-year-old son,” said Vaughn. “I get to tell him: We’re staying here. We’re proud of being from Alabama.”