  The North American Nanohertz Observatory for Gravitational Waves (NANOGrav)
collaboration has recently reported strong evidence for a stochastic process
affecting the 12.5 yr dataset of pulsar timing residuals. We show that the
signal can be interpreted in terms of a stochastic gravitational wave
background emitted from a network of axionic strings in the early Universe. The
spontaneous breaking of the Peccei-Quinn symmetry originate the axionic string
network and the QCD axion, the dark matter particle in the model. We explore a
non-standard cosmological model driven by an exotic scalar field $\phi$ which
evolves under the influence of a self-interacting potential; the axion field
starts to oscillate during the modified cosmology, and provides the dark matter
observed. For an equation of state $w_\phi < 1/3$, the QCD axion mass is
smaller than expected in the standard cosmology and the GW spectrum from
axionic strings is larger. We assess the parameter space of the model which is
consistent with the NANOGrav-$12.5\,$yr detection, which can be explained
within 95\% limit by a QCD axion field evolving in a dust-like scenario, as
well as within 68\% limit in a cosmology with $w_\phi < 0$.
