  A search for heavy neutral leptons (HNLs), the right-handed Dirac or Majorana
neutrinos, is performed in final states with three charged leptons (electrons
or muons) using proton-proton collision data collected by the CMS experiment at
$\sqrt{s} =$ 13 TeV at the CERN LHC. The data correspond to an integrated
luminosity of 138 fb$^{-1}$. The HNLs could be produced through mixing with
standard model neutrinos $\nu$. For small values of the HNL mass ($\lt$ 20 GeV)
and the square of the HNL-$\nu$ mixing parameter (10$^{-7}$-10$^{-2}$), the
decay length of these particles can be large enough so that the secondary
vertex of the HNL decay can be resolved with the CMS silicon tracker. The
selected final state consists of one lepton emerging from the primary
proton-proton collision vertex, and two leptons forming a displaced, secondary
vertex. No significant deviations from the standard model expectations are
observed, and constraints are obtained on the HNL mass and coupling strength
parameters, excluding previously unexplored regions of parameter space in the
mass range 1-20 GeV and squared mixing parameter values as low as 10$^{-7}$.
