Accreting T Tauri stars are observed to be less luminous in X-rays than non-accretors, an effect that has been detected in various star-forming regions. To explain this we have combined, for the first time, a radiative transfer code with an accretion model that considers magnetic fields extrapolated from surface magnetograms obtained from Zeeman-Doppler imaging. Such fields consist of compact magnetic regions close to the stellar surface, with extended field lines interacting with the disc. We study the propagation of coronal X-rays through the magnetosphere and demonstrate that they are strongly absorbed by the dense gas in accretion columns. The reduction in the observed X-ray emission depends on the field geometry, which may explain why ...