Metal-halide perovskites (MHPs) have been successfully exploited for converting photons to charges or vice versa in applications of solar cells, light-emitting diodes and solar fuels1-3, for which all these applications involve strong light. Here we show that self-powered polycrystalline perovskite photodetectors can rival the commercial silicon photomultipliers (SiPMs) for photon counting. The photon-counting capability of perovskite photon-counting detectors (PCDs) is mainly determined by shallow traps, despite that deep traps also limit charge-collection efficiency. Two shallow traps with energy depth of 5.8 ± 0.8 millielectronvolts (meV) and 57.2 ± 0.1 meV are identified in polycrystalline methylammonium lead triiodide, which mainly stay at grain boundaries and the surface, respectively. We show that these shallow traps can be reduced by grain-size enhancement and surface passivation using diphenyl sulfide, respectively. It greatly suppresses dark count rate (DCR) from >20,000 counts per second per square millimetre (cps mm-2) to 2 cps mm-2 at room temperature, enabling much better response to weak light than SiPMs. The perovskite PCDs can collect γ-ray spectra with better energy resolution than SiPMs and maintain performance at high temperatures up to 85 °C. The zero-bias operation of perovskite detectors enables no drift of noise and detection property. This study opens a new application of photon counting for perovskites that uses their unique defect properties.