The origin of ferromagnetism in strained epitaxial LaCoO3 films has been a long-standing mystery. Here, we combine atomically resolved Z-contrast imaging, electron-energy-loss spectroscopy, and density-functional calculations to demonstrate that, in epitaxial LaCoO3 films, oxygen-vacancy superstructures release strain, control the film's electronic properties, and produce the observed ferromagnetism via the excess electrons in the Co d states. Although oxygen vacancies typically dope a material n-type, we find that ordered vacancies induce Peierls-like minigaps which, combined with strain relaxation, trigger a nonlinear rupture of the energy bands, resulting in insulating behavior. [ABSTRACT FROM AUTHOR]