The Canada-France-Hawaii Telescope Lensing Survey (CFHTLenS) comprises deep multi-colour (u*griz) photometry spanning 154 square degrees, with accurate photometric redshifts and shape measurements. We demonstrate that the redshift probability distribution function summed over galaxies provides an accurate representation of the galaxy redshift distribution accounting for random and catastrophic errors for galaxies with best fitting photometric redshifts z_p < 1.3. We present cosmological constraints using tomographic weak gravitational lensing by large-scale structure. We use two broad redshift bins 0.5 < z_p <= 0.85 and 0.85 < z_p <= 1.3 free of intrinsic alignment contamination, and measure the shear correlation function on angular scales in the range ~1-40 arcmin. We show that the problematic redshift scaling of the shear signal, found in previous CFHTLS data analyses, does not afflict the CFHTLenS data. For a flat Lambda-CDM model and a fixed matter density Omega_m=0.27, we find the normalisation of the matter power spectrum sigma_8=0.771 pm 0.041. When combined with cosmic microwave background data (WMAP7), baryon acoustic oscillation data (BOSS), and a prior on the Hubble constant from the HST distance ladder, we find that CFHTLenS improves the precision of the fully marginalised parameter estimates by an average factor of 1.5-2. Combining our results with the above cosmological probes, we find Omega_m=0.2762 pm 0.0074 and sigma_8=0.802 pm 0.013.