Feedback loops are central to most classical control procedures. A controller compares the signal measured by a sensor (system output) with the target value or set-point. It then adjusts an actuator (system input) to stabilize the signal around the target value. Generalizing this scheme to stabilize a micro-system’s quantum state relies on quantum feedback1, 2, 3, which must overcome a fundamental difficulty: the sensor measurements cause a random back-action on the system. An optimal compromise uses weak measurements4, 5, providing partial information with minimal perturbation. The controller should include the effect of this perturbation in the computation of the actuator’s operation, which brings the incrementally perturbed state closer to the target. Although some aspects of this scenario have been experimentally demonstrated for the control of quantum6, 7, 8, 9 or classical10, 11 micro-system variables, continuous feedback loop operations that permanently stabilize quantum systems around a target state have not yet been realized. Here we have implemented such a real-time stabilizing quantum feedback scheme12 following a method inspired by ref. 13. It prepares on demand photon number states (Fock states) of a microwave field in a superconducting cavity, and subsequently reverses the effects of decoherence-induced field quantum jumps14, 15, 16. The sensor is a beam of atoms crossing the cavity, which repeatedly performs weak quantum non-demolition measurements of the photon number14. The controller is implemented in a real-time computer commanding the actuator, which injects adjusted small classical fields into the cavity between measurements. The microwave field is a quantum oscillator usable as a quantum memory17 or as a quantum bus swapping information between atoms18. Our experiment demonstrates that active control can generate non-classical states of this oscillator and combat their decoherence15, 16, and is a significant step towards the implementation of complex quantum information operations.