Khalid, a Democrat, was unsettled by the fact that someone had posted her address on social media. But she was also worried that the hate-fueled attacks would become a distraction. So she deleted her Facebook account, asked friends to look out for worrisome comments, and went back to pounding the streets with her leaflets and her clipboard.

On Tuesday night, she won her race by a significant margin. The victory, she told supporters, showed that “community organizers beat Internet trolls.”