By counting curves over finite fields, one obtains a wealth of information about the cohomology of moduli spaces of curves and of principally polarized abelian varieties. Galois representations or mixed Hodge structures (or, in ideal cases, motives) associated to modular forms make their appearance. The modular forms are elliptic cusp forms for SL(2,Z) in genus 1, Siegel cusp forms in genera 2 and 3, and, on the moduli space M_3 of curves of genus 3, the first so-called Teichmüller modular forms have recently been detected. This is a report on joint work with Jonas Bergström and Gerard van der Geer.