A search for a heavy neutral lepton N of Majorana nature decaying into a W boson and a charged lepton is performed using the CMS detector at the LHC. The targeted signature consists of three prompt charged leptons in any flavor combination of electrons and muons. The data were collected in proton-proton collisions at a center-of-mass energy of 13 TeV, with an integrated luminosity of 35.9 fb−1. The search is performed in the N mass range between 1 GeV and 1.2 TeV. The data are found to be consistent with the expected standard model background. Upper limits are set on the values of |VeN|2 and |VμN|2, where VℓN is the matrix element describing the mixing of N with the standard model neutrino of flavor ℓ. These are the first direct limits for N masses above 500 GeV and the first limits obtained at a hadron collider for N masses below 40 GeV.