Voters file in to vote after standing in a long line that leads out the doors of the Beulah Baptist Church polling station in Montgomery, Ala., on Tuesday. (Jim Watson/AFP/Getty Images)

DeJuana Thompson spent Alabama's election night at a party where "I Voted" stickers were the price of entry — one more bash for Woke Vote, an organization that had spent $400,000 to turn out young black voters. Thompson, a Birmingham native, had joined Woke Vote's get-out-the-vote drive when it looked impossible for Democrat Doug Jones to win.

On Tuesday, surrounded by cheering black voters, Thompson watched Jones pull it off.

"I was without words," Thompson said. "It was reminiscent of the night we elected Obama. People did not believe it could happen, and then, suddenly, it did."

The Alabama race, like last month's elections in Virginia, saw Democrats outperform expectations and polling thanks to a surge of nonwhite voters. A year that began with hand-wringing over President Trump's victory ended with routs and upsets powered by the party's most loyal supporters. Democrats in Alabama and elsewhere spent Wednesday thanking black voters — and studying what had been so successful in getting them to the polls.

"Let me be clear: We won in Alabama and Virginia because black women led us to victory," said Democratic National Committee chairman Tom Perez. "Black women are the backbone of the Democratic Party, and we can't take that for granted. Period."

Now, Perez and other Democrats said, they have a road map to follow in next year's midterm elections, where they hope to make gains in battlegrounds with large nonwhite populations, including Nevada, Arizona and even Texas.

Perez highlighted the DNC's quiet strategy in Alabama, a $1 million investment in millennial and black voter turnout that was not advertised until the election was won. That was just one of the efforts that paid off for Democrats in Alabama, where new third-party groups including Woke Vote and BlackPAC engaged in weeks of voter persuasion and targeted messages.

"They are underneath the radar, and that's why they work so beautifully," said Cornell Belcher, a pollster for Barack Obama's presidential campaigns who has warned Democrats that younger black voters feel taken for granted. "They didn't just come in at the end and treat black voters like get-out-the-vote targets. They treated them like persuadable voters. They actually engaged on the top issue for African American voters, which is criminal justice reform. And they didn't dance around the issue of police brutality."

Everything came together in Alabama, from the unique appeal of Jones — a man who had prosecuted Klansmen and served on the board of Birmingham's Civil Rights Institute — to Moore's gaffes about slavery and felon voter rights restoration. On Election Day, voter turnout in Alabama's "black belt" was as high as 75 percent of normal presidential election turnout. In Moore's largely white strongholds, turnout plunged below 45 percent of that norm.

Democrats' opportunities had largely come from Moore, who never recovered from allegations of improper sexual conduct with teenage girls. But even Jones supporters described Alabama's Democratic Party as hollowed out, decimated by losses under Obama and the subsequent gerrymandering of state and federal legislative districts.

The opportunity to stop yet another Republican win proved irresistible. Bridget Jones, a 51-year-old Realtor in Montgomery, said that she'd voted against "the good old boys crew," and believed Jones when he said Alabama would hurt its image if it let Moore into the Senate.

"Just sit back and wait," Jones said. "I think we're going to look like a better state for those who looked at us as backward."

Jones's margin depended not just on engaged voters, but on black voters who might have sat out other elections. Laquana Jackson, who had moved to Montgomery from Brooklyn, had been skeptical about Alabama but gave Jones a chance.

"I feel defeated at some points, but I still have to try," she said. "It's been one way for so long, for so many years."

Community organizer T. Marie King brought her mother to Charles A. Brown Elementary School in Birmingham to vote for Jones. During the campaign, King had spoken out on what she saw as Jones's failure to connect with black voters on policy.

"I obviously know what he did to prosecute white supremacists years ago, but I don't know what he has done for the black community lately," she said after dropping her mother off at the polling place.

But King wanted Jones to win, certain that he would be a better choice for black Alabamians than Moore — a man like Trump, she said, in his desire to drive the country backward. In interviews at King's polling place, two dozen black voters said they did not feel inspired to show up for Jones, who they felt did not aggressively pursue their vote. They were moved to wait in line — some for hours — to keep Moore from winning.

Getting black voters to that point had taken some work. Jones's campaign deployed some traditional methods of turning out black voters, fully funding the turnout operation run by Joe Reed, who leads the state's Alabama Democratic Conference. It had supplemented that with a tough, direct ad campaign that sometimes drew criticism. A piece of direct mail that showed a black man raising his eyebrow asked if a black man would ever get away with what Moore was accused of — a message that was condemned by both Fox News and the liberal-leaning black news site the Root.

According to Reed, all of it worked.

"Of course black folk can't get away with what white folks get away with!" he said. "Hell, I could name 10 or 12 more things that black folks would get in trouble for but white folks can get away with."

What was ignored in some coverage of the mailer was its contents — a series of attacks on Moore's civil rights record. The Jones campaign, the first in Alabama to put together a winning coalition of black voters and white liberals and moderates since the 1990s, did not concentrate on converting conservative former Democrats.

That message was recognizable to Sen. Tim Kaine (D-Va.), who started his electoral career by courting black voters to win office in Richmond. A friend of Jones for years, he kept in touch with the campaign, and was reassured at times that the campaign was doing what was necessary to activate the Democratic base.

Democrats worried about that, in part, because black political strategists had demanded they do more. In May, a number of black female Democrats, led by Glynda Carr, published an open letter to Perez and the DNC, warning that people like them had been ignored.

"We have voted and organized our communities with little support or investment from the Democratic Party for voter mobilization efforts," the women wrote. "Black women voters are the very foundation to a winning coalition, yet most Black voters feel like the Democrats take them for granted."

Perez met with the women in June, but according to Carr, just as important was the flowering of independent black political organizations that ran their own voter persuasion campaigns. As in Virginia, BlackPAC worked somewhat under the radar to message to black voters. Woke Vote, focusing on college campuses, knocked on thousands of doors.

"You don't need to put all your eggs into the DNC basket," said Carr. "We need more of these organizations, and we need them to scale up. Because when you organize a black woman, she doesn't come by herself. She brings her house, her block, her church, and her sorority."

On social media, starting Tuesday night, black political strategists celebrated the belated attention that the turnout operations were getting — a change, at last, from coverage of frustrated Trump voters. And on Wednesday, at his first news conference as Alabama's senator-elect, Jones ribbed some members of the media for missing the black vote. Asked how his campaign turned out Alabama's nonwhite voters, the Democrat asked why so many people thought he couldn't.

"I didn't read all you folks in the national media with that criticism," Jones said, "because I knew you were wrong."

Kayla Epstein in Montgomery, Ala., contributed to this report.