This paper provides new evidence on the effect of immigration on election outcomes. Our analysis makes use of data on city districts in Hamburg, Germany, during a period of substantial inflows of immigrants and asylum seekers. We find significant and robust effects for changes in foreigner shares on the electoral success of parties that built up a distinctive reputation in immigration politics. In particular, our fixed-effects estimates indicate a positive effect for xenophobic, extreme right-wing parties and an adverse effect for the Green party that actively campaigned for liberal immigration policies and minority rights. Overall, our results support the hypothesis that changes in local compositional amenities shape individual attitudes towards immigration.