Flying insects have evolved sophisticated sensory-motor systems, and here we argue that such systems are used to keep upright against intrinsic flight instabilities. We describe a theory that predicts the instability growth rate in body pitch from flapping-wing aerodynamics and reveals two ways of achieving balanced flight: active control with sufficiently rapid reactions and passive stabilization with high body drag. By glueing magnets to fruit flies and perturbing their flight using magnetic impulses, we show that these insects employ active control that is indeed fast relative to the instability. Moreover, we find that fruit flies with their control sensors disabled can keep upright if high-drag fibres are also attached to their bodies, an observation consistent with our prediction for the passive stability condition. Finally, we extend this framework to unify the control strategies used by hovering animals and also furnish criteria for achieving pitch stability in flapping-wing robots.