We propose a mechanism for the generation of magnetic fields on cosmological scales that is operative after recombination. An essential ingredient is an instability (of parametric resonance type) of the electromagnetic field driven by an oscillating pseudo-scalar dark matter field, \phi, that is coupled to the electromagnetic field tensor via a \phi F \wedge F term in the Lagrangian of axion-electrodynamics. We find that magnetic fields larger than the observational lower bounds can be generated soon after recombination on scales of 1 {\rm{Mpc}}.