We determine the maximal dimension of compact subvarieties of Ag, the moduli space of complex principally polarized abelian varieties of dimension g, and the maximal dimension of a compact subvariety through a very general point of Ag. This also allows us to draw some conclusions for compact subvarieties of the moduli space of complex curves of compact type.