Cold, dense clouds in the interstellar medium of our Galaxy are 4–5 orders of magnitude denser than their diffuse counterparts. Our Solar System has most likely encountered at least one of these dense clouds during its lifetime. However, evidence for such an encounter has not been studied in detail yet. Here we derive the velocity field of the Local Ribbon of Cold Clouds (LRCC) by modelling the 21 cm data from the HI4PI survey, finding that the Solar System may have passed through the LRCC in the constellation Lynx 2–3 million years ago. Using a state-of-the-art simulation of the heliosphere, we show that during the passage, the heliosphere shrinks to a scale of 0.22 au, smaller than the Earth’s orbit around the Sun. This would have put the Earth in direct contact with the dense interstellar medium for a period of time and exposed it to a neutral hydrogen density above 3,000 cm−3. Such a scenario agrees with geological evidence from 60Fe and 244Pu isotopes. The encounter and related increased radiation from Galactic cosmic rays might have had a substantial impact on the Earth’s system and climate. Modelling suggests that the Solar System may have passed through a cold dense cloud 2–3 Myr ago, in agreement with geological evidence from 60Fe and 244Pu isotopes, putting Earth in direct contact with the dense interstellar medium with potentially substantial impacts on its climate.