Observations of the molecular gas phase in quasar host galaxies provide fundamental constraints on galaxy evolution at the highest redshifts. Molecular gas is the material out of which stars form; it can be traced by spectral line emission of carbon--monoxide (CO). To date, CO emission has been detected in more than a dozen quasar host galaxies with redshifts (z) larger 2, the record holder being at z=4.69. At these distances the CO lines are shifted to longer wavelengths, enabling their observation with sensitive radio and millimetre interferometers. Here we present the discovery of CO emission toward the quasar SDSS J114816.64+525150.3 (hereafter J1148+5251) at a redshift of z=6.42, when the universe was only 1/16 of its present age. This is the first detection of molecular gas at the end of cosmic reionization. The presence of large amounts of molecular gas (M(H_2)=2.2e10 M_sun) in an object at this time demonstrates that heavy element enriched molecular gas can be generated rapidly in the earliest galaxies.