A search for a new Z^{'} gauge boson associated with (un)broken B-L symmetry in the keV-GeV mass range is carried out for the first time using the missing-energy technique in the NA64 experiment at the CERN SPS. From the analysis of the data with 3.22×10^{11} electrons on target collected during 2016-2021 runs, no signal events were found. This allows us to derive new constraints on the Z^{'}-e coupling strength, which, for the mass range 0.3≲m_{Z^{'}}≲100 MeV, are more stringent compared to those obtained from the neutrino-electron scattering data.