Searches for the exclusive decays of the Higgs and Z bosons into a J/ψ, ψ(2S), or ϒ(nS) (n=1,2,3) meson and a photon are performed with a pp collision data sample corresponding to an integrated luminosity of 36.1fb collected at s=13TeV with the ATLAS detector at the CERN Large Hadron Collider. No significant excess of events is observed above the expected backgrounds, and 95% confidence-level upper limits on the branching fractions of the Higgs boson decays to J/ψγ, ψ(2S)γ, and ϒ(nS)γ of 3.5×10 , 2.0×10 , and (4.9,5.9,5.7)×10 , respectively, are obtained assuming Standard Model production. The corresponding 95% confidence-level upper limits for the branching fractions of the Z boson decays are 2.3×10 , 4.5×10 and (2.8,1.7,4.8)×10 , respectively. −1 −4 −3 −4 −6 −6 −