We present a mechanism for the origin of the large-scale curvature perturbation in our Universe by the late decay of a massive scalar field, the curvaton. The curvaton is light during a period of cosmological inflation, when it acquires a perturbation with an almost scale-invariant spectrum. This corresponds initially to an isocurvature density perturbation, which generates the curvature perturbation after inflation when the curvaton density becomes a significant fraction of the total. The isocurvature density perturbation disappears if the curvaton completely decays into thermalised radiation. Any residual isocurvature perturbation is 100% correlated with the curvature. The same mechanism can also generate the curvature perturbation in pre-big bang/ekpyrotic models, provided that the curvaton has a suitable non-canonical kinetic term so as to generate a flat spectrum.