We report the results of a search for a new vector boson ($A$) decaying into two dark matter particles $chi_1 chi_2$ of different mass. The heavier $chi_2$ particle subsequently decays to $chi_1$ and $A to e^- e^+$. For a sufficiently large mass splitting, this model can explain in terms of new physics the recently confirmed discrepancy observed in the muon anomalous magnetic moment at Fermilab. Remarkably, it also predicts the observed yield of thermal dark matter relic abundance. A detailed Monte-Carlo simulation was used to determine the signal yield and detection efficiency for this channel in the NA64 setup. The results were obtained re-analyzing the previous NA64 searches for an invisible decay $Ato chi overline{chi}$ and axion-like or pseudo-scalar particles $a to gamma gamma$. With this method, we exclude a significant portion of the parameter space justifying the muon g-2 anomaly and being compatible with the observed dark matter relic density for $A$ masses from 2$m_e$ up to 390 MeV and mixing parameter $epsilon$ between $3times10^{-5}$ and $2times10^{-2}$.