Context. The study of Earth-mass extrasolar planets via the radial-velocity technique and the measurement of the potential cosmological variability of fundamental constants call for very-high-precision spectroscopy at the level of δλ/λ < 10−9. Only an accurate wavelength calibration of the spectrograph can guarantee that the aimed precision is achieved over a multi-exposure and multi-epoch data set. Wavelength accuracy is obtained by providing two fundamental ingredients: 1) an absolute and information-rich wavelength source and 2) the ability of the spectrograph and its data reduction of transferring the reference scale (wavelengths) to a measurement scale (detector pixels) in a repeatable manner. Aims. The goal of this work is to improve the wavelength calibration accuracy of the HARPS spectrograph by combining the absolute spectral reference provided by the emission lines of a thorium-argon hollow-cathode lamp (HCL) with the spectrally rich and precise spectral information of a Fabry-Pérot-based calibration source. Methods. On the basis of calibration frames acquired each night since the Fabry-Pérot etalon was installed on HARPS in 2011, we constructed a combined wavelength solution that fits simultaneously the thorium emission lines and the Fabry-Pérot lines. The combined fit was anchored to the absolute thorium wavelengths, which provide the “zero-point” of the spectrograph, while the Fabry-Pérot lines were used to improve the (spectrally) local precision. The obtained wavelength solution was verified for auto-consistency and tested against a solution obtained using the HARPS laser-frequency comb (LFC). Results. The combined thorium+Fabry-Pérot wavelength solution shows significantly better performances compared to the thorium-only calibration. In both cases, the residuals of the LFC line positions to the fitted wavelength solution follow a Gaussian distribution with an rms value of about 14 m s−1 for the combined solution, and twice as large for the thorium-only solution (29 m s−1). Given these positive results, we have applied the new calibrations to scientific frames and tested the radial-velocity residual on three well-known stars: HD 10700, HD 20794, and HD 69830. In all three cases the radial-velocity (RV) scatter could be reduced compared to the measurements using the previous calibration. Conclusions. The richness of the Fabry-Pérot spectrum helps to improve the wavelength calibration using thorium-argon lamps or extending the wavelength domain of LFCs with limited operational range. The presented techniques will therefore be used in the new HARPS and HARPS-N pipeline, and will be exported to the ESPRESSO spectrograph.