  This paper concerns the K band Hubble diagram for the brightest cluster
galaxies (BCGs) in a sample of X-ray clusters covering the redshift range
$0.05<z<0.8$. We show that BCGs in clusters of high X-ray luminosity are
excellent standard candles: the intrinsic dispersion in the raw K band absolute
magnitudes of BCGs in clusters with $L_{\rm X} > 2.3 \times 10^{44}$ erg
s$^{-1}$ (in the 0.3 - 3.5 keV band) is no more than 0.22 mag, and is not
significantly reduced by correcting for the BCG structure parameter, $\alpha$,
or for X-ray luminosity. This is the smallest scatter in the absolute
magnitudes of any single class of galaxy and demonstrates the homogeneity of
BCGs in high-$L_{\rm X}$ clusters. By contrast, we find that the brightest
members of low-$L_{\rm X}$ systems display a wider dispersion ($\sim 0.5$ mag)
in absolute magnitude than commonly seen in previous studies, which arises from
the inclusion, in X-ray flux-limited samples, of poor clusters and groups which
are usually omitted from low redshift studies of BCGs in optically rich
clusters....[abstract shortened].. The BCGs in our high-$L_{\rm X}$ clusters
yield a value of $\Omega_{\rm M}=0.28\pm0.24$ if the cosmological constant
$\Lambda=0$. For a flat Universe we find $\Omega_{\rm M}=0.55^{+0.14}_{-0.15}$
with a 95 per cent confidence upper limit to the cosmological constant
corresponding to $\Omega_{\Lambda}<0.73$. These results are discussed in the
context of other methods used to constrain the density of the Universe, such as
Type Ia supernovae.
