A search for long-lived particles decaying to photons and weakly interacting particles, using proton-proton collision data at s=13  TeV collected by the CMS experiment in 2016–2017 is presented. The data set corresponds to an integrated luminosity of 77.4  fb-1. Results are interpreted in the context of supersymmetry with gauge-mediated supersymmetry breaking, where the neutralino is long-lived and decays to a photon and a gravitino. Limits are presented as a function of the neutralino proper decay length and mass. For neutralino proper decay lengths of 0.1, 1, 10, and 100 m, masses up to 320, 525, 360, and 215 GeV are excluded at 95% confidence level, respectively. We extend the previous best limits in the neutralino proper decay length by up to one order of magnitude, and in the neutralino mass by up to 100 GeV.