Mammalian genomes employ heritable cytosine methylation in the long-term silencing of retrotransposons and genes subject to genomic imprinting and X chromosome inactivation. Little is known of the mechanisms that direct cytosine methylation to specific sequences. Here we show that DNA methyltransferase 3-like (Dnmt3L (ref. 1)) is expressed in testes during a brief perinatal period in the non-dividing precursors of spermatogonial stem cells at a stage where retrotransposons undergo de novo methylation. Deletion of the Dnmt3L gene prevented the de novo methylation of both long-terminal-repeat (LTR) and non-LTR retrotransposons, which were transcribed at high levels in spermatogonia and spermatocytes. Loss of Dnmt3L from early germ cells also caused meiotic failure in spermatocytes, which do not express Dnmt3L. Whereas dispersed repeated sequences were demethylated in mutant germ cells, tandem repeats in pericentric regions were methylated normally. This result indicates that the Dnmt3L protein might have a function in the de novo methylation of dispersed repeated sequences in a premeiotic genome scanning process that occurs in male germ cells at about the time of birth.