The fundamental function of any oscillator is to produce a waveform with a stable frequency. Here, we show a method of frequency stabilization for spin-torque nano-oscillators (STNOs) that relies on coupling with an adjacent nanomagnet through the magnetic dipole–dipole interaction. It is numerically demonstrated that highly stable oscillations occur as a result of mutual feedback between an STNO and a nanomagnet. The nanomagnet acts as a nonlinear resonator for the STNO. This method is based on the nonlinear behavior of the resonator and can be considered as a magnetic analogue of an optimization scheme in nanoelectromechanical systems. The oscillation frequency is most stabilized when the nanomagnet is driven at a special feedback point at which the feedback noise between the STNO and resonator is completely eliminated.