We realize a heat engine using a single electron spin as a working medium. The spin pertains to the valence electron of a trapped $^{40}$Ca$^+$ ion, and heat reservoirs are emulated by controlling the spin polarization via optical pumping. The engine is coupled to the ion's harmonic-oscillator degree of freedom via spin-dependent optical forces. The motion stores the work produced by the heat engine and therefore acts as a flywheel. We fully characterize the heat engine by measuring the temporally varying spin polarization and the state of the flywheel by reconstructing its Husimi $\mathcal{Q}$ function. We infer the deposited energy and the work fluctuations for varying engine runtimes in the onset of operation, starting in the oscillator ground state. We also determine the ergotropy, i.e. the maximum amount of work which can be extracted via a cyclic unitary.