We report the results of a search for a light pseudoscalar particle $a$ that couples to electrons and decays to $e^+e^-$ performed using the high-energy CERN SPS H4 electron beam. If such pseudoscalar with a mass $\simeq 17$ MeV exists, it could explain the ATOMKI anomaly. We used the NA64 data samples collected in the "visible mode" configuration with total statistics corresponding to $8.4\times 10^{10}$ electrons on target (EOT) in 2017 and 2018. In order to increase sensitivity to small coupling parameter $\epsilon$ we used also the data collected in 2016-2018 in the "invisible mode" configuration of NA64 with a total statistics corresponding to $2.84\times 10^{11}$ EOT. A thorough analysis of both these data samples in the sense of background and efficiency estimations was already performed and reported in our previous papers devoted to the search for light vector particles and axion-like particles (ALP). In this work we recalculate the signal yields, which are different due to different cross section and life time of a pseudoscalar particle $a$, and perform a new statistical analysis. As a result, the region of the two dimensional parameter space $m_a - \epsilon$ in the mass range from 1 to 17.1 MeV is excluded. At the mass of the ATOMKI anomaly the values of $\epsilon$ in the range $2.1 \times 10^{-4} < \epsilon < 3.2 \times 10^{-4}$ are excluded.