  A search for the production of pairs of heavy Majorana neutrinos (N$_\ell$)
from the decays of Z' bosons is performed using the CMS detector at the LHC.
The data were collected in proton-proton collisions at a center-of-mass energy
of $\sqrt{s}$ = 13 TeV, with an integrated luminosity of 138 fb$^{-1}$. The
signature for the search is an excess in the invariant mass distribution of the
final-state objects, two same-flavor leptons (e or $\mu$) and at least two
jets. No significant excess of events beyond the expected background is
observed. Upper limits at 95% confidence level are set on the product of the Z'
production cross section and its branching fraction to a pair of N$_\ell$, as
functions of N$_\ell$ and Z' boson masses ($m_{\mathrm{N}_\ell}$ and
$m_\mathrm{Z'}$, respectively) for $m_\mathrm{Z'}$ from 0.4 to 4.6 TeV and
$m_{\mathrm{N}_\ell}$ from 0.1 TeV to $m_\mathrm{Z'}$/2. In the theoretical
framework of a left-right symmetric model, exclusion bounds in the
$m_{\mathrm{N}_\ell}-m_\mathrm{Z'}$ plane are presented in both the electron
and muon channels. The observed upper limit on $m_\mathrm{Z'}$ reaches up to
4.42 TeV. These are the most restrictive limits to date on the mass of N$_\ell$
as a function of the Z' boson mass.
