Democrats were counting on a rapid burst of diversification in the U.S. fueled by immigration to help Hillary Clinton. But it may have helped put Donald Trump in the White House.

The more rapidly a county has diversified since the start of this century, the more likely voters there were to cast ballots for the Republican nominee, a Wall Street Journal analysis of voting results and census data shows. It appears to be one reason Mr. Trump turned some traditional blue states into red states, including Wisconsin.

The...