Abstract. We investigate magnetic field geometry and surface distribution of chemical elements in the rapidly oscillating Ap star HR 3831. Results of the model atmosphere analysis of the spectra of this star are combined with the Hipparcos parallax and evolutionary models to obtain new accurate estimates of the fundamental stellar parameters: T eff = 7650 K, log L/L = 1.09, M/M = 1.77 and an inclination angle i = 68• of the stellar axis of rotation. We find that the variation of the longitudinal magnetic field of HR 3831 and the results of our analysis of the magnetic intensification of Fe lines in the spectrum of this star are consistent with a dipolar magnetic topology with a magnetic obliquity β = 87• and a polar strength B p = 2.5 kG. We apply a multi-element abundance Doppler imaging inversion code for the analysis of the spectrum variability of HR 3831, and recover surface distributions of 17 chemical elements, including Li, C, O, Na, Mg, Si, Ca, Ti, Cr, Mn, Fe, Co, Ba, Y, Pr, Nd, Eu. Our study represents the most thorough examination of the surface chemical structure in a magnetic Ap star and provides important observational constraints for modelling radiative diffusion in magnetic stars. The exceedingly high quality of some of our spectroscopic data allowed us to reconstruct unprecedented details of abundance distributions, demonstrating a high level of complexity in the surface structure down to the resolution limit of the Doppler maps. The Doppler imaging analysis of HR 3831 forms a basis for subsequent detailed observational investigations and theoretical modelling of non-radial oscillations in this star. We discuss the compound effect of the chemical nonuniformities and pulsational velocity field on the rapid line profile variations, and assess the possibility of identifying pulsation modes by using spatial filtering produced by an inhomogeneous abundance distribution. The results of our study of the surface chemical structure suggest that differences in pulsational behaviour of lines of different ions observed for HR 3831 are not a consequence of horizontal atmospheric inhomogeneities, but predominantly a depth effect.