On Mars, clay minerals are widespread in terrains that date back to the Noachian period (4.1 billion to 3.7 billion years ago)1,2,3,4,5. It is thought that the Martian basaltic crust reacted with liquid water during this time to form hydrated clay minerals3,6. Here we propose, however, that a substantial proportion of these clays was formed when Mars’ primary crust reacted with a dense steam or supercritical atmosphere of water and carbon dioxide that was outgassed during magma ocean cooling7,8,9. We present experimental evidence that shows rapid clay formation under conditions that would have been present at the base of such an atmosphere and also deeper in the porous crust. Furthermore, we explore the fate of a primordial clay-rich layer with the help of a parameterized crustal evolution model; we find that the primordial clay is locally disrupted by impacts and buried by impact-ejected material and by erupted volcanic material, but that it survives as a mostly coherent layer at depth, with limited surface exposures. These exposures are similar to those observed in remotely sensed orbital data from Mars1,2,3,4,5. Our results can explain the present distribution of many clays on Mars, and the anomalously low density of the Martian crust in comparison with expectations.