We present cosmological results from the final galaxy clustering data set of the Baryon Oscillation Spectroscopic Survey, part of the Sloan Digital Sky Survey III. Our combined galaxy sample comprises 1.2 million massive galaxies over an effective area of 9329 deg2 and volume of 18.7 Gpc3, divided into three partially overlapping redshift slices centred at effective redshifts 0.38, 0.51 and 0.61. We measure the angular diameter distance DM and Hubble parameter H from the baryon acoustic oscillation (BAO) method, in combination with a cosmic microwave background prior on the sound horizon scale, after applying reconstruction to reduce non-linear effects on the BAO feature. Using the anisotropic clustering of the pre-reconstruction density field, we measure the product DMH from the Alcock–Paczynski (AP) effect and the growth of structure, quantified by fσ8(z), from redshift-space distortions (RSD). We combine individual measurements presented in seven companion papers into a set of consensus values and likelihoods, obtaining constraints that are tighter and more robust than those from any one method; in particular, the AP measurement from sub-BAO scales sharpens constraints from post-reconstruction BAOs by breaking degeneracy between DM and H. Combined with Planck 2016 cosmic microwave background measurements, our distance scale measurements simultaneously imply curvature ΩK = 0.0003 ± 0.0026 and a dark energy equation-of-state parameter w = −1.01 ± 0.06, in strong affirmation of the spatially flat cold dark matter (CDM) model with a cosmological constant (ΛCDM). Our RSD measurements of fσ8, at 6 per cent precision, are similarly consistent with this model. When combined with supernova Ia data, we find H0 = 67.3 ± 1.0 km s−1 Mpc−1 even for our most general dark energy model, in tension with some direct measurements. Adding extra relativistic species as a degree of freedom loosens the constraint only slightly, to H0 = 67.8 ± 1.2 km s−1 Mpc−1. Assuming flat ΛCDM, we find Ωm = 0.310 ± 0.005 and H0 = 67.6 ± 0.5 km s−1 Mpc−1, and we find a 95 per cent upper limit of 0.16 eV c−2 on the neutrino mass sum.