In recent years, several optimal dynamos have been discovered. They minimize the magnetic energy dissipation or, equivalently, maximize the growth rate at a fixed magnetic Reynolds number. In the optimal dynamo of Willis (Phys. Rev. Lett., vol. 109, 2012, 251101), we find mean-field dynamo action for planar averages. One component of the magnetic field grows exponentially while the other decays in an oscillatory fashion near onset. This behaviour is different from that of an $\unicode[STIX]{x1D6FC}^{2}$ dynamo, where the two non-vanishing components of the planar averages are coupled and have the same growth rate. For the Willis dynamo, we find that the mean field is excited by a negative turbulent magnetic diffusivity, which has a non-uniform spatial profile near onset. The temporal oscillations in the decaying component are caused by the corresponding component of the diffusivity tensor being complex when the mean field is decaying and, in this way, time dependent. The growing mean field can be modelled by a negative magnetic diffusivity combined with a positive magnetic hyperdiffusivity. In two other classes of optimal dynamos of Chen et al. (J. Fluid Mech., vol. 783, 2015, pp. 23–45), we find, to some extent, similar mean-field dynamo actions. When the magnetic boundary conditions are mixed, the two components of the planar averaged field grow at different rates when the dynamo is 15 % supercritical. When the mean magnetic field satisfies homogeneous boundary conditions (where the magnetic field is tangential to the boundary), mean-field dynamo action is found for one-dimensional averages, but not for planar averages. Despite having different spatial profiles, both dynamos show negative turbulent magnetic diffusivities. Our finding suggests that negative turbulent magnetic diffusivities may support a broader class of dynamos than previously thought, including these three optimal dynamos.