The mechanism that produces energetic electrons during magnetic reconnection is poorly understood. This is a fundamental process responsible for stellar flares 1,2 , substorms 3,4 , and disruptions in fusion experiments 5,6 . Observations in the solar chromosphere 1 and the Earth's magnetosphere 7-10 indicate significant electron acceleration during reconnection, whereas in the solar wind, energetic electrons are absent 11 . Here we show that energetic electron acceleration is caused by unsteady reconnection. In the Earth's magnetosphere and the solar chromosphere, reconnection is unsteady, so energetic electrons are produced; in the solar wind, reconnection is steady 12 , so energetic electrons are absent 11 . The acceleration mechanism is quasi-adiabatic: betatron and Fermi acceleration in outflow jets are two processes contributing to electron energization during unsteady reconnection. The localized betatron acceleration in the outflow is responsible for at least half of the energy gain for the peak observed fluxes.