We performed a search for a new generic X boson, which could be a scalar (S), pseudoscalar (P), vector (V), or an axial vector (A) particle produced in the 100 GeV electron scattering off nuclei, e^{-}Z→e^{-}ZX, followed by its invisible decay in the NA64 experiment at CERN. No evidence for such a process was found in the full NA64 dataset of 2.84×10^{11} electrons on target. We place new bounds on the S, P, V, A coupling strengths to electrons, and set constraints on their contributions to the electron anomalous magnetic moment a_{e}, |Δa_{X}|≲10^{-15}-10^{-13} for the X mass region 1 MeV≲m_{X}≲1 GeV. These results are an order of magnitude more sensitive compared to the current accuracy on a_{e} from the electron g-2 experiments and recent high-precision determination of the fine structure constant.