Generating the curvature perturbation at the end of inflation