Aims. Even the most precise radial-velocity instruments gather high-resolution spectra that present systematic errors that a data reduction pipeline cannot identify and correct for efficiently by simply analysing a set of calibrations and a single science frame. In this paper we aim at improving the radial-velocity precision of HARPS measurements by 'cleaning' individual extracted spectra using the wealth of information contained in spectral time series. Methods. We developed YARARA, a post-processing pipeline designed to clean high-resolution spectra of instrumental systematics and atmospheric contamination. Spectra are corrected for: tellurics, interference patterns, detector stitching, ghosts, and fibre B contaminations, as well as more advanced spectral line-by-line corrections. YARARA uses principal component analysis on spectral time series with prior information to disentangle contaminations from real Doppler shifts. We applied YARARA to three systems, HD10700, HD215152, and HD10180, and compared our results to the standard HARPS data reduction software and the SERVAL post-processing pipeline.Results. We ran YARARA on the radial-velocity dataset of three stars intensively observed with HARPS: HD10700, HD215152, and HD10180. For HD10700, we show that YARARA enables us to obtain radial-velocity measurements that present an rms smaller than 1 m s −1 over the 13 years of the HARPS observations, which is 20% and 10% better than the HARPS data reduction software and the SERVAL post-processing pipeline, respectively. We also injected simulated planets into the data of HD10700 and demonstrated that YARARA does not alter pure Doppler-shifted signals. For HD215152, we demonstrated that the 1-year signal visible in the periodogram becomes marginal after processing with YARARA and that the signals of the known planets become more significant. Finally, for HD10180, the six known exoplanets are well recovered, although different orbital parameters and planetary masses are provided by the new reduced spectra. Conclusions. The post-processing correction of spectra using spectral time series allows the radial-velocity precision of HARPS data to be significantly improved and demonstrates that for the extremely quiet star HD10700 a radial-velocity rms better than 1 m/s can be reached over the 13 years of HARPS observations. Since the processing proposed in this paper does not absorb planetary signals, its application to intensively followed systems is promising and will certainly result in advances in the detections of the lightest exoplanets.