The composition, texture and genetic evolution of kerolite and related Mg clays belonging to the Intermediate Unit of the Miocene from the Madrid Basin have been studied. About 400 samples from the Esquivias deposit were analysed by several mineralogical and/or chemical techniques. Two genetic pathways for the development of Mg clays during early diagenesis have been observed: (1) mudflat environment: Al-smectite (beidellite)-->Mg-smectite (saponite); and (2) palustrine environment: Si-Mg gel-->kerolite-->kerolite-stevensite-->stevensite. In the mudflat deposit the transformation processes predominate, whilst in the palustrine environment, kerolite is neoformed, probably from a gel-like medium. Stevensite seems to have originated from the transformation of mixed-layer kerolite-Mg-smectite, but also through neoformation at a later stage. The textural features, isotopic data and sedimentary evolution within each lithofacies are indicative of shallowing-upward sequences with development of palaeosols. A post-sedimentary origin for sepiolite, calcite, authigenic quartz, zeolites and baryte is inferred.