Using data from the last 150 years in a small set of countries, and from the postwar period in a large set of countries, we show that large investments in state primary education systems tend to occur when countries face military rivals or threats from their neighbors. By contrast, we find that democratic transitions are negatively associated with education investments, while the presence of democratic political institutions magnifies the positive effect of military rivalries. These empirical results are robust to a number of statistical concerns and continue to hold when we instrument military rivalries with commodity prices or rivalries in a certain country's immediate neighborhood. We also present historical case studies, as well as a simple model, that are consistent with the econometric evidence. * We thank Xavier Jaravel for superb research assistance. We are also grateful to Tim Besley, Nick Bloom, Jim Fearon, Claudia Goldin, Elhanan Helpman, Kalina Manova, Nathan Nunn, and Francesco Trebbi for help and suggestions, and to seminar participants at Harvard, Brown, Stanford GSB, and the Canadian Institute for Advanced Research (CIFAR) program meeting for useful comments. Financial support from the ERC and the Torsten and Ragnar Söcerberg Foundations is gratefully acknowledged.