A search for a Higgs boson decaying into a pair of electrons or muons plus a photon is described. This final state has contributions from Higgs decays to a boson and a photon (\mathrm{H}\rightarrow \mathrm{Z}\gamma\rightarrow \ell\ell\gamma~,~\ell=\mathrm{e} or ), or to two photons, one of which has an internal conversion into a lepton pair (). The analysis is performed using a dataset recorded by the CMS experiment at the LHC from proton-proton collisions at a center-of-mass energy of 13~\mathrm{TeV}, corresponding to an integrated luminosity of 35.9~\mathrm{fb}^{-1}. No significant excess above the background prediction has been found in the 120-130~\mathrm{GeV} mass range. Limits are set on the cross section for a standard model Higgs boson decaying to opposite-sign electron or muon pairs and a photon. The observed limits on cross section times the corresponding branching fractions fluctuate between 4 and 1.4 (11 and 6) times the standard model cross section for (). The and analyses are combined for m_\mathrm{H}=125~\mathrm{GeV}, obtaining an observed (expected) upper limit of 3.9 (2.0) times the standard model cross section.