We present our studies of the forward unpolarised doubly-virtual Compton scattering (VVCS) off the deuteron and the closely related two-photon-exchange ($2\gamma$-exchange) corrections to the Lamb shift of muonic deuterium. The deuteron VVCS amplitude is calculated in the framework of pionless effective field theory, up to next-to-next-to-next-to-leading order (N3LO) for the longitudinal and next-to-leading order (NLO) for the transverse amplitude. The charge elastic form factor of the deuteron, obtained from the residue of the longitudinal VVCS amplitude, is used to extract the value of the single unknown two-nucleon one-photon contact coupling that enters the longitudinal amplitude at N3LO. The obtained deuteron VVCS amplitude serves as a high-precision model-independent input to examine the $2\gamma$-exchange corrections. Substantial differences with the recent dispersive evaluations are identified, namely, the elastic contribution appears to be larger by several standard deviations, thus ameliorating the current discrepancy between theory and experiment on the size of $2\gamma$-exchange effects.
A correlation between the values of the deuteron charge and Friar radii is found that can be used to judge on the quality of a parametrisation of the deuteron charge elastic form factor. The discrepancy between the theory and the empirical result for the $2\gamma$-exchange correction in muonic deuterium appears to be completely eliminated. To further confirm this, we revisit the hydrogen-deuterium isotope shift in the same framework. Our work provides an alternative self-consistent and high-precision evaluation of the $2\gamma$-exchange correction in (muonic) deuterium.