The African malaria mosquito Anopheles gambiae is diversifying into ecotypes known as M and S forms. This process is thought to be promoted by adaptation to different larval habitats, but its genetic underpinnings remain elusive. To identify candidate targets of divergent natural selection in M and S, we performed genomewide scanning in paired population samples from Mali, followed by resequencing and genotyping from five locations in West, Central, and East Africa. Genome scans revealed a significant peak of M-S divergence on chromosome 3L, overlapping five known or suspected immune response genes. Resequencing implicated a selective target at or near the TEP1 gene, whose complement C3-like product has antiparasitic and antibacterial activity. Sequencing and allele-specific genotyping showed that an allelic variant of TEP1 has been swept to fixation in M samples from Mali and Burkina Faso and is spreading into neighboring Ghana, but is absent from M sampled in Cameroon, and from all sampled S populations. Sequence comparison demonstrates that this allele is related to, but distinct from, TEP1 alleles of known resistance phenotype. Experimental parasite infections of advanced mosquito intercrosses demonstrated a strong association between this TEP1 variant and resistance to both rodent malaria and the native human malaria parasite Plasmodium falciparum. Although malaria parasites may not be direct agents of pathogen-mediated selection at TEP1 in nature--where larvae may be the more vulnerable life stage--the process of adaptive divergence between M and S has potential consequences for malaria transmission.