State Rep. Ed Gainey won the four-way primary race for Pittsburgh mayor, positioning himself to become the first Black mayor in the city's history.