Democrat Doug Jones has won the special election to fill a Senate seat in Alabama, according to exit polls and returns — a shocking upset in a solidly Republican state, in which massive turnout among African American voters helped defeat a candidate enthusiastically backed by President Trump. The Associated Press called the race at 10:23 p.m. Eastern time. With about 98 percent of precincts reporting, Jones was leading by about 10,000 votes, with 49.5 percent of the vote as compared to Republican Roy Moore’s 48.8 percent.

It appeared that write-in candidates played a key role in the race: combined, they got 22,000 votes, more than the gap between the winner and the loser. Richard C. Shelby (R), Alabama’s other senator, had appeared to encourage the state’s Republicans to choose that option: Shelby said he wrote the name of an undisclosed “distinguished Republican” rather than vote for Moore. Just after 11 p.m. Eastern time, Trump congratulated Jones in a Twitter message, saying “The write-in votes played a very big factor, but a win is a win. The people of Alabama are great, and the Republicans will have another shot at this seat in a very short period of time.”

Moore, however, refused to concede the race. Speaking to supporters at about 11:34 p.m. Eastern time, Moore said he thought the race might go to a recount, which state law requires when a race is within 0.5 percentage points. “When the vote is this close . . . it’s not over,” Moore said. Jones’ lead, at that point, however, still exceeded 0.5 percent. Then, Moore – who had spent much of his campaign railing against the news media – asked that the press visit the Alabama secretary of state and ask how the recount provision might be triggered in this case – that “the press will go up there and talk to them to find out what the situation is.”

“What we’ve got to do is wait on God,” Moore said. Jones would become the first Democrat elected to the Senate from Alabama since 1992. The Senate seat came open when Trump chose Jeff Sessions to become attorney general earlier this year.