Selection at one site shapes patterns of genetic variability of nearby sites. Both the fixation of advantageous mutations (selective sweeps) and the removal of deleterious mutations (background selection) can reduce genetic diversity at nearby sites. However, the relative importance of recurrent positive selection and background selection is not well understood. The observation of a negative correlation between levels of synonymous site variability (πS) and the rate of protein evolution (KA) in genes across the genome of Drosophila melanogaster has been interpreted as support for a major role of recurrent positive selection. However, background selection can also cause such a pattern when recombination within a gene is sufficiently low. This means that genes under lower selective constraints are more susceptible to background selection and may show less genetic variation. Here we analyse the patterns of genetic variation across the autosomal genes of an African D. melanogaster population to test these predictions, taking into account the effects of other genomic features that covary with πS and KA. The results suggest that both background selection and recurrent positive selection determine the negative relation between synonymous diversity and protein sequence divergence.