Context. Many novel methods have been proposed to mitigate stellar activity for exoplanet detection as the presence of stellar activity in radial velocity (RV) measurements is the current major limitation. Unlike traditional methods that model stellar activity in the RV domain, more methods are moving in the direction of disentangling stellar activity at the spectral level. As deep neural networks have already been proven to be one of the most effective tools in data mining, in this work, we explore their potential in the context of Earth-like planet detection in RV measurements. Aims. The goal of this paper is to present a novel convolutional neural network-based algorithm that efficiently models stellar activity signals at the spectral level, enhancing the detection of Earth-like planets. Methods. Based on the idea that the presence of planets can only produce a Doppler shift at the spectral level while the presence of stellar activity can introduce a variation in the profile of spectral lines (asymmetry and depth change), we trained a convolutional neural network to build the correlation between the change in the spectral line profile and the corresponding RV, full width at half maximum (FWHM) and bisector span (BIS) values derived from the classical cross-correlation function. Results. This algorithm has been tested on three intensively observed stars: Alpha Centauri B (HD 128621), Tau ceti (HD 10700), and the Sun. By injecting simulated planetary signals at the spectral level, we demonstrate that our machine learning algorithm can achieve, for HD 128621 and HD 10700, a detection threshold of 0.5 m s−1 in semi-amplitude for planets with periods ranging from 10 to 300 days. This threshold would correspond to the detection of a ~4 M⊕ in the habitable zone of those stars. On the HARPS-N solar dataset, thanks to significantly more data, our algorithm is even more efficient at mitigating stellar activity signals and can reach a threshold of 0.2 m s−1, which would correspond to a 2.2 M⊕ planet on the orbit of the Earth. Conclusions. To the best of our knowledge, it is the first time that such low detection thresholds are reported for the Sun, but also for other stars, and therefore this highlights the efficiency of our convolutional neural network-based algorithm at mitigating stellar activity in RV measurements.