  Thermal dark matter models with particle $\chi$ masses below the electroweak
scale can provide an explanation for the observed relic dark matter density.
This would imply the existence of a new feeble interaction between the dark and
ordinary matter. We report on a new search for the sub-GeV $\chi$ production
through the interaction mediated by a new vector boson, called the dark photon
$A'$, in collisions of 100 GeV electrons with the active target of the NA64
experiment at the CERN SPS. With $9.37\times10^{11}$ electrons on target
collected during 2016-2022 runs NA64 probes for the first time the
well-motivated region of parameter space of benchmark thermal scalar and
fermionic dark matter models. No evidence for dark matter production has been
found. This allows us to set the most sensitive limits on the $A'$ couplings to
photons for masses $m_{A'} \lesssim 0.35$ GeV, and to exclude scalar and
Majorana dark matter with the $\chi-A'$ coupling $\alpha_D \leq 0.1$ for masses
$0.001 \lesssim m_\chi \lesssim 0.1$ GeV and $3m_\chi \leq m_{A'}$.
