A major theory from social psychology claims that external threats can strengthen group identities and cooperation. This paper exploits the Russian invasion in Ukraine 2014 as a sudden increase in the perceived military threat for eastern European Union member states, in particular for the Baltic countries bordering Russia directly. Comparing low versus high-threat member states in a difference-in-differences design, I find a sizeable positive effect on EU identity. It is associated with higher trust in EU institutions and support for common EU policies. Different perceptions of the invasion cause a polarization of preferences between the majority and ethnic Russian minorities.