We present a new method based on a Bayesian hierarchical model to extract constraints on cosmological parameters from Type Ia supernova (SNIa) data obtained with the SALT-II light-curve fitter. We demonstrate with simulated data sets that our method delivers tighter statistical constraints on the cosmological parameters over 90 per cent of the time, that it reduces statistical bias typically by a factor of ∼2–3 and that it has better coverage properties than the usual χ2 approach. As a further benefit, a full posterior probability distribution for the dispersion of the intrinsic magnitude of SNe is obtained. We apply this method to recent SNIa data, and by combining them with cosmic microwave background and baryonic acoustic oscillations data, we obtain Ωm= 0.28 ± 0.02, ΩΛ= 0.73 ± 0.01 (assuming w=−1) and Ωm= 0.28 ± 0.01, w=−0.90 ± 0.05 (assuming flatness; statistical uncertainties only). We constrain the intrinsic dispersion of the B-band magnitude of the SNIa population, obtaining σintμ= 0.13 ± 0.01 mag. Applications to systematic uncertainties will be discussed in a forthcoming paper.