Identifying galaxy clusters through overdensities of galaxies in photometric surveys is the oldest and arguably the most economic and mass-sensitive detection method, compared to X-ray and Sunyaev-Zel'dovich Effect surveys that detect the hot intracluster medium. However, a perennial problem has been the mapping of optical 'richness' measurements on to total cluster mass. Emitted at a conformal distance of 14 Gpc, the cosmic microwave background acts as a backlight to all intervening mass in the Universe, and therefore has been gravitationally lensed. Here we present a calibration of cluster optical richness at the 10 per cent level by measuring the average cosmic microwave background lensing convergence measured by Planck towards the positions of large numbers of optically-selected clusters, detecting the deflection of photons by haloes of total mass of the order 10**14 solar masses. Although mainly aimed at the study of larger-scale structures, the Planck lensing reconstruction can yield nearly unbiased results for stacked clusters on arcminute scales. The lensing convergence only depends on the redshift integral of the fractional overdensity of matter, so this approach offers a clean measure of cluster mass over most of cosmic history, largely independent of baryon physics.