Hold-up capacitor
A large capacitor whose only job is to keep the circuit alive for the milliseconds it takes to tidy up after a power cut.
When the supply disappears the voltage doesn't drop instantly, and how slowly it falls is something you can design. A capacitor holds ½CV², so the hold-up time is the energy difference between the starting voltage and the lowest voltage the circuit tolerates, divided by the power draw. A diode in front stops the capacitor from feeding the rest of the board, so the reserve goes only to the microcontroller and its memory.
The classic mistake is counting on time to erase. A flash sector can take hundreds of milliseconds or more to erase, far longer than any sensible capacitor will last. Firmware meant to survive power loss therefore erases ahead of time and writes only the final record when the PVD interrupt arrives. That is, whatever fits — not whatever you'd like.