Then ISIS struck. On November 13, terrorists killed 130 people and wounded more than 400 in Paris. Trump called for a database to track Muslims in the United States. A week later, he boasted that “people look at me as a strong leader. The polls have been very much up since” the attack.

He was right. And it was the beginning of a pattern. For the next nine months, violence kept striking American and European cities. Trump kept responding in reckless, bigoted ways—and profiting at the polls.

Read: An oral history of Trump’s bigotry

On December 2, a married couple in San Bernardino sympathetic to ISIS killed 14 people and injured 22. A few days later, Trump called for a “total and complete shutdown of Muslims entering the United States.” He also noted that “whenever there’s a tragedy … my numbers go way up.” It was true. As FiveThirtyEight’s Nate Silver later noted, Trump’s national poll numbers, which “had stagnated in the mid-to-high 20s in the two months before Paris,” rose to 32 percent after the Paris attacks and 35 percent after San Bernardino. Trump never trailed in the GOP race again.

Then, in late March, suicide bombings in Belgium killed 35 people and wounded more than 300. Trump declared that “I would close up our borders to people until we figure out what is going on” and “do a lot more than waterboarding” to suspected terrorists. As March turned to April, his lead over his closest rivals, Ted Cruz and John Kasich, kept expanding. “I’ve been talking about this simply much more than anybody else,” Trump said in response to the Brussels attacks, “and it’s why I’m probably number one in the polls because of the fact that I say we have to have strong borders.”

The next major jihadist attack occurred on June 12 when Omar Mateen, who had pledged loyalty to the Islamic State, killed 49 people and wounded 53 others at a gay nightclub in Orlando. Trump reiterated his call for a ban on Muslim immigration, and in the days that followed gained modestly on Hillary Clinton in general-election polls.

Read: Will Trump’s racist attacks help him? Ask blue-collar white women.

Finally, on July 8, an African American man seeking revenge for police violence against blacks shot and killed five white policemen in Dallas. Ten days later, when the Republican Convention began, Clinton’s lead—which had averaged six to seven points in June—was down to three points. At the convention, Trump made the attacks a centerpiece of his acceptance speech. “Our convention occurs at a moment of crisis for our nation,” he declared. “The attacks on our police, and the terrorism in our cities, threaten our very way of life.” Trump’s speech used the word murder twice, brutal three times, police five times, crime seven times, killing nine times, and violence 11 times. By the convention’s end, he had a small lead.