We study the long-term determinants of the high rates of HIV infection in sub-Saharan Africa, particularly among women, with a focus on family structure and sexual behavior as shaped by the demographic shock following the transatlantic slave trade. First we show that, in clusters where polygyny is more widespread, HIV infection rates are higher. By instrumenting polygyny with the demographic shock we can also establish that this link is causal. Next we turn to the channels through which polygyny is likely to affect HIV infection by focusing on sexual behavior, as captured by the intensity of sexual activity and the frequency of extramarital partnerships. We document relevant gender differences in behavior: in clusters affected by a larger demographic shock men (but not women) display a more intense sexual activity, while women (but not men) are more likely to engage in extramarital partnerships. We employ these findings to instrument sexual behavior when estimating its influence on HIV infection and we show that clusters exhibiting more frequent female extramarital partnerships are affected by significantly higher infection rates. We interpret our results as follows. The demographic shock induced by the slave trade represents a "primordial" risk factor which is still shaping contemporary family structure and sexual behavior. Polygyny is associated with unsatisfying marital relationships, particularly for women, with consequent female infidelity and an increased risk of infection, which is further multiplied for women co-habiting within polygynous households.