HIV latency is the chief obstacle to eradicating HIV but is widely believed to be an evolutionary accident providing no lentiviral fitness advantage. However, findings of latency being “hardwired” into HIV’s gene-regulatory circuitry appear inconsistent with latency being an evolutionary accident, given HIV’s rapid mutation rate. Here, we propose that latency is an evolutionary “bet-hedging” strategy whose frequency has been optimized to maximize lentiviral transmission by reducing viral extinction during mucosal infections. The model quantitatively fits the available patient data, matches observations of high-frequency latency establishment in cell culture and primates, and generates two counterintuitive but testable predictions. The first prediction is that conventional CD8-depletion experiments in SIV-infected macaques increase latent cells more than viremia. The second prediction is that strains engineered to have higher replicative fitness—via reduced latency—will exhibit lower infectivity in animal-model mucosal inoculations. Therapeutically, the theory predicts treatment approaches that may substantially enhance “activate-and-kill” HIV-cure strategies.