Solar flares -bursts of high-energy radiation responsible for severe space-weather effects -are a consequence of the occasional destabilization of magnetic fields rooted in active regions (ARs). The complexity of AR evolution is a barrier to a comprehensive understanding of flaring processes and accurate prediction. Though machine learning (ML) has been used to improve flare predictions, the potential for revealing precursors and associated physics has been underexploited. Here, we train ML algorithms to classify between vectormagnetic-field observations from flaring ARs, producing at least one M-/X-class flare, and non-flaring ARs. Analysis of magnetic-field observations accurately classified by the machine presents statistical evidence for (1) ARs persisting in flare-productive states -characterized by AR area -for days, before and after M-and X-class flare events, (2) systematic pre-flare build-up of free energy in the form of electric currents, suggesting that associated subsurface magnetic field is twisted, (3) intensification of Maxwell stresses in the corona above newly emerging ARs, days before first flares. These results provide new insights into flare physics and improving flare forecasting.Solar Flares | Space Weather | Solar Magnetic Fields | Machine Learning