The near-Earth carbonaceous asteroid (162173) Ryugu is expected to contain volatile chemical species that could provide information on the origin of Earth's volatiles. Samples of Ryugu were retrieved by the Hayabusa2 spacecraft. We measured noble gas and nitrogen isotopes in Ryugu samples and found that they are dominated by presolar and primordial components, incorporated during Solar System formation. Noble gas concentrations are higher than those in Ivuna-type carbonaceous (CI) chondrite meteorites. Several host phases of isotopically distinct nitrogen have different abundances among the samples. Our measurements support a close relationship between Ryugu and CI chondrites. Noble gases produced by galactic cosmic rays, indicating a ~5 million year exposure, and from implanted solar wind record the recent irradiation history of Ryugu after it migrated to its current orbit.