All solar flares demonstrate a prolonged, hourlong post-flare (or gradual) phase, characterized by arcade-like, post-flare loops (PFLs) visible in many extreme ultraviolet (EUV) passbands. These coronal loops are filled with hot – ~30MK – and dense plasma, evaporated from the chromosphere during the impulsive phase of the flare, and they very gradually recover to normal coronal density and temperature conditions. During this gradual cooling down to ~1MK regimes, much cooler – ~0.01MK – and denser coronal rain is frequently observed inside PFLs. Understanding PFL dynamics in this long-duration, gradual phase is crucial to the entire corona-chromosphere mass and energy cycle. Here we report the first simulation in which a solar flare evolves from pre-flare, over impulsive phase all the way into its gradual phase, which successfully reproduces post-flare coronal rain. This rain results from catastrophic cooling caused by thermal instability, and we analyse the entire mass and energy budget evolution driving this sudden condensation phenomenon. We find that the runaway cooling and rain formation also induces the appearance of dark post-flare loop systems, as observed in EUV channels. We confirm and augment earlier observational findings, suggesting that thermal conduction and radiative losses alternately dominate the cooling of PFLs. Since reconnection-driven flares occur in many astrophysical settings (stellar flares, accretion disks, galactic winds and jets), our study suggests a new and natural pathway to introduce multi-thermal structuring.