The inhomogeneity of an electron spin ensemble as well as fluctuating environment acting upon individual spins drastically shorten the spin coherence time $T_2$ and hinder coherent spin manipulation. We show that this problem can be solved by the simultaneous application of a radiofrequency (rf) field, which stimulates coherent spin precession decoupled from an inhomogeneous environment, and periodic optical pulses, which amplify this precession. The resulting resonance, taking place when the rf field frequency approaches the laser pulse repetition frequency, has a width determined by the spin coherence time $T_2$ that is free from the inhomogeneity effects. We measure a 50-Hz-narrow electron spin resonance and milliseconds-long $T_2$ for electrons in the ground state of Ce$^{3+}$ ions in the YAG lattice at low temperatures, while the inhomogeneous spin dephasing time $T_2^*$ is only 25 ns. This study paves the way to coherent optical manipulation in spin systems decoupled from their inhomogeneous environment.