Treatment as prevention (TasP) has been proposed by the World Health Organization and the Joint United Nations Programme on HIV/AIDS (UNAIDS) as a global strategy for eliminating HIV. The rationale is that treating individuals reduces their infectivity. We present a geostatistical framework for designing TasP-based HIV elimination strategies in sub-Saharan Africa. We focused on Lesotho, where ~25% of the population is infected. We constructed a density of infection map by gridding high-resolution demographic data and spatially smoothing georeferenced HIV testing data. The map revealed the countrywide geographic dispersion pattern of HIV-infected individuals. We found that ~20% of the HIV-infected population lives in urban areas and that almost all rural communities have at least one HIV-infected individual. We used the map to design an optimal elimination strategy and identified which communities should use TasP. This strategy minimized the area that needed to be covered to find and treat HIV-infected individuals. We show that UNAIDS’s elimination strategy would not be feasible in Lesotho because it would require deploying treatment in areas where there are ~4 infected individuals/km2. Our results show that the spatial dispersion of Lesotho’s population hinders, and may even prevent, the elimination of HIV.