Cometary nuclei consist mostly of dust and water ice1. Previous observations have found nuclei to be low-density and highly porous bodies2,3,4, but have only moderately constrained the range of allowed densities because of the measurement uncertainties. Here we report the precise mass, bulk density, porosity and internal structure of the nucleus of comet 67P/Churyumov–Gerasimenko on the basis of its gravity field. The mass and gravity field are derived from measured spacecraft velocity perturbations at fly-by distances between 10 and 100 kilometres. The gravitational point mass isGM= 666.2 ± 0.2 cubic metres per second squared, giving a massM= (9,982 ± 3) × 109 kilograms. Together with the current estimate of the volume of the nucleus5, the average bulk density of the nucleus is 533 ± 6 kilograms per cubic metre. The nucleus appears to be a low-density, highly porous (72–74 per cent) dusty body, similar to that of comet 9P/Tempel 12,3. The most likely composition mix has approximately four times more dust than ice by mass and two times more dust than ice by volume. We conclude that the interior of the nucleus is homogeneous and constant in density on a global scale without large voids. The high porosity seems to be an inherent property of the nucleus material.