A search for the production of pairs of heavy Majorana neutrinos (Nl) 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 √s = 13TeV, 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 μ) 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 Nl, as functions of Nl and Z′ boson masses (mNl and mZ′ , respectively) for mZ′ from 0.4 to 4.6TeV and mNl from 0.1TeV to mZ′/2. In the theoretical framework of a left-right symmetric model, exclusion bounds in the mNl -mZ′ plane are presented in both the electron and muon channels. The observed upper limit on mZ′ reaches up to 4.42TeV. These are the most restrictive limits to date on the mass of Nl as a function of the Z′ boson mass.