Imprinted methylation of the paternal Rasgrf1 allele in mice occurs at a differentially methylated domain (DMD) 30 kbp 5' of the promoter. A repeated sequence 3' of the DMD regulates imprinted methylation, which is required for imprinted expression. Here we identify the mechanism by which methylation controls imprinting. The DMD is an enhancer blocker that binds CTCF in a methylation-sensitive manner. CTCF bound to the unmethylated maternal allele silences expression. CTCF binding to the paternal allele is prevented by repeat-mediated methylation, allowing expression. Optimal in vitro enhancer-blocking activity requires CTCF binding sites. The enhancer blocker can be bypassed in vivo and imprinting abolished by placing an extra enhancer proximal to the promoter. Together, the repeats and the DMD constitute a binary switch that regulates Rasgrf1 imprinting.