We present a comprehensive analysis of weak gravitational lensing by large-scale structure in the Hubble Space Telescope Cosmic Evolution Survey (COSMOS), in which we combine space-based galaxy shape measurements with ground-based photometric redshifts to study the redshift dependence of the lensing signal and constrain cosmological parameters. After applying our weak lensingoptimized data reduction, principal-component interpolation for the spatially, and temporally varying ACS point-spread function, and improved modelling of charge-transfer inefficiency, we measured a lensing signal that is consistent with pure gravitational modes and no significant shape systematics. We carefully estimated the statistical uncertainty from simulated COSMOS-like fields obtained from ray-tracing through the Millennium Simulation, including the full non-Gaussian sampling variance. We tested our lensing pipeline on simulated space-based data, recalibrated non-linear power spectrum corrections using the ray-tracing analysis, employed photometric redshift information to reduce potential contamination by intrinsic galaxy alignments, and marginalized over systematic uncertainties. We find that the weak lensing signal scales with redshift as expected from general relativity for a concordance ΛCDM cosmology, including the full cross-correlations between different redshift bins. Assuming a flat ΛCDM cosmology, we measure σ 8 (Ω m /0.3) 0.51 = 0.75 ± 0.08 from lensing, in perfect agreement with WMAP-5, yielding joint constraints Ω m = 0.266 +0.025 −0.023 , σ 8 = 0.802 +0.028 −0.029 (all 68.3% conf.). Dropping the assumption of flatness and using priors from the HST Key Project and Big-Bang nucleosynthesis only, we find a negative deceleration parameter q 0 at 94.3% confidence from the tomographic lensing analysis, providing independent evidence of the accelerated expansion of the Universe. For a flat wCDM cosmology and prior w ∈ [−2, 0], we obtain w < −0.41 (90% conf.). Our dark energy constraints are still relatively weak solely due to the limited area of COSMOS. However, they provide an important demonstration of the usefulness of tomographic weak lensing measurements from space.