This is an example of a heterozygote advantage otherwise called overdominance.
In genetics, overdominance is a ohenomenon where the heterozygote has greater fitness compared to both the recessive and the dominant homozygote. In this case, natural selection favors the heterozygote genotype.
G6PD deficiency is an example of overdominance very similar to the one of sickle cell anemia heterozygote dominance. In both of the cases dominant homozygotes are healthy, but vulnerable to malaria and recessive homozygote carriers develop serious medical conditions. The heterozygotes have one recessive allele that is making defective, non functional red blood cell proteins, but the other allele still produces normal protein, so the medical condition is not present. The cell machinery in these individuals is very active in getting rid of the defective cells, eliminating the malaria parasite on the way. Therefore, the heterozygote carriers don't have health problems and are protected from malaria and have the advantage over the homozygotes.