For more than two hours on Tuesday night, many Americans bit their nails and glued themselves to a screen as the votes rolled in.

Then, in a matter of minutes, media outlets — in rapid succession — called the Alabama Senate race for Doug Jones, a Democrat who defeated Roy S. Moore, a Republican accused of sexual abuse and child molestation.

And almost as quickly, high-profile politicians took to Twitter to weigh in.

Just after 11 p.m., President Trump congratulated Mr. Jones on his favored platform, arguing that “the write-in votes played a very big factor” in the outcome, though he also acknowledged that “a win is a win.”

About 22,800 write-in votes had been counted. Just before midnight on Tuesday, Mr. Jones was more than 20,000 votes ahead of Mr. Moore with all the precincts having reported. (Mr. Moore did not concede defeat late Tuesday.)