  We study magnetogenesis in axionlike inflation driven by a pseudoscalar field
$\phi$ coupled axially to the electromagnetic (EM) field $(\beta/M_{p})\phi
F_{\mu\nu}\tilde{F}^{\mu\nu}$ with dimensionless coupling constant $\beta$. A
set of equations for the inflaton field, scale factor, and expectation values
of quadratic functions of the EM field is derived. These equations take into
account the Schwinger effect and the backreaction of generated EM fields on the
Universe expansion. It is found that the backreaction becomes important when
the EM energy density reaches the value $\rho_{\rm EM}\sim
(\sqrt{2\epsilon}/\beta)\rho_{\rm inf}$ ($\epsilon$ is the slow-roll parameter
and $\rho_{\rm inf}$ is the energy density of the inflaton) slowing down the
inflaton rolling and terminating magnetogenesis. The Schwinger effect becomes
relevant when the electric energy density exceeds the value $\rho_{E}\sim
\alpha_{\rm EM}^{-3} (\rho_{\rm tot}^{2}/M_{p}^{4})$, where $\rho_{\rm
tot}=3H^{2}M_{p}^{2}$ is the total energy density and $\alpha_{\rm EM}$ is the
EM coupling constant. For large $\beta$, produced charged particles could
constitute a significant part of the Universe energy density even before the
preheating stage. Numerically studying magnetogenesis in the $\alpha$-attractor
model of inflation, we find that it is possible to generate helical magnetic
fields with the maximal strength $10^{-15}\,{\rm G}$, however, only with the
correlation length of order $1\,{\rm pc}$ at present.
