We present constraints on cosmological parameters using number counts as a function of redshift for a sub-sample of 189 galaxy clusters from the Planck SZ (PSZ) catalogue. The PSZ is selected through the signature of the Sunyaev--Zeldovich (SZ) effect, and the sub-sample used here has a signal-to-noise threshold of seven, with each object confirmed as a cluster and all but one with a redshift estimate. We discuss the completeness of the sample and our construction of a likelihood analysis. Using a relation between mass $M$ and SZ signal $Y$ calibrated to X-ray measurements, we derive constraints on the power spectrum amplitude $sigma_8$ and matter density parameter $Omega_{mathrm{m}}$ in a flat $Lambda$CDM model. We test the robustness of our estimates and find that possible biases in the $Y$--$M$ relation and the halo mass function are larger than the statistical uncertainties from the cluster sample. Assuming the X-ray determined mass to be biased low relative to the true mass by between zero and 30%, motivated by comparison of the observed mass scaling relations to those from a set of numerical simulations, we find that $sigma_8=0.75pm 0.03$, $Omega_{mathrm{m}}=0.29pm 0.02$, and $sigma_8(Omega_{mathrm{m}}/0.27)^{0.3} = 0.764 pm 0.025$. The value of $sigma_8$ is degenerate with the mass bias; if the latter is fixed to a value of 20% we find $sigma_8(Omega_{mathrm{m}}/0.27)^{0.3}=0.78pm 0.01$ and a tighter one-dimensional range $sigma_8=0.77pm 0.02$. We find that the larger values of $sigma_8$ and $Omega_{mathrm{m}}$ preferred by Plancks measurements of the primary CMB anisotropies can be accommodated by a mass bias of about 40%. Alternatively, consistency with the primary CMB constraints can be achieved by inclusion of processes that suppress power on small scales relative to the $Lambda$CDM model, such as a component of massive neutrinos (abridged).