Antiretroviral therapy (ART) is increasingly being used as an HIV-prevention tool, administered to uninfected people with ongoing HIV exposure as pre-exposure prophylaxis (PrEP) and to infected people to reduce their infectiousness. We used a modelling approach to determine the optimal population-level combination of ART and PrEP allocations required in South Africa to maximize programme effectiveness for four outcome measures: new infections, infection-years, death and cost. We considered two different strategies for allocating treatment, one that selectively allocates drugs to sex workers and one that does not. We found that for low treatment availability, prevention through PrEP to the general population or PrEP and ART to sex workers is key to maximizing effectiveness, while for higher drug availability, ART to the general population is optimal. At South Africa's current level of treatment availability, using prevention is most effective at reducing new infections, infection-years, and cost, while using the treatment as ART to the general population best reduces deaths. At treatment levels that meet the UNAIDS's ambitious new 90-90-90 target, using all or almost all treatment as ART to the general population best reduces all four outcome measures considered.