Transitional millisecond pulsars are an emerging class of sources that link low-mass X-ray binaries to millisecond radio pulsars in binary systems. These pulsars alternate between a radio pulsar state and an active low-luminosity X-ray disc state. During the active state, these sources exhibit two distinct emission modes (high and low) that alternate unpredictably, abruptly, and incessantly. X-ray to optical pulsations are observed only during the high mode. The root cause of this puzzling behaviour remains elusive. This paper presents the results of the most extensive multi-wavelength campaign ever conducted on the transitional pulsar prototype, PSR J1023+0038, covering from the radio to X-rays. The campaign was carried out over two nights in June 2021 and involved 12 different telescopes and instruments, including XMM-Newton, HST, VLT/FORS2 (in polarimetric mode), ALMA, VLA, and FAST. By modelling the broadband spectral energy distributions in both emission modes, we show that the mode switches are caused by changes in the innermost region of the accretion disc. These changes trigger the emission of discrete mass ejections, which occur on top of a compact jet, as testified by the detection of at least one short-duration millimetre flare with ALMA at the high-to-low mode switch. The pulsar is subsequently re-enshrouded, completing our picture of the mode switches.