  Context. We have investigated the multiwavelength emission of PSR J2021+4026,
the only isolated gamma-ray pulsar known to be variable, which in October 2011
underwent a simultaneous change in gamma-ray flux and spin-down rate, followed
by a second mode change in February 2018. Multiwavelength monitoring is crucial
to understand the physics behind these events and how they may have affected
the structure of the magnetosphere. Aims.The monitoring of pulse profile
alignment is a powerful diagnostic tool for constraining magnetospheric
reconfiguration. We aim to investigate timing or flux changes related to the
variability of PSR J2021+4026 via multiwavelength observations, including
gamma-ray observations from Fermi-LAT, X-ray observations from XMM-Newton, and
a deep optical observation with the Gran Telescopio Canarias.Methods. We
performed a detailed comparison of the timing features of the pulsar in gamma
and X-rays and searched for any change in phase lag between the phaseogram
peaks in these two energy bands. Although previous observations did not detect
a counterpart in visible light, we also searched for optical emission that
might have increased due to the mode change, making this pulsar detectable in
the optical. Results.We have found a change in the gamma-to X-ray pulse profile
alignment by 0.21$\pm$0.02 in phase, which indicates that the first mode change
affected different regions of the pulsar magnetosphere. No optical counterpart
was detected down to g'=26.1 and r'=25.3. Conclusions.We suggest that the
observed phase shift could be related to a reconfiguration of the connection
between the quadrupole magnetic field near the stellar surface and the dipole
field that dominates at larger distances. This is consistent with the picture
of X-ray emission coming from the heated polar cap and with the simultaneous
flux and frequency derivative change observed during the mode changes.
