Background: Development of vaccines against human immunodeficiency virus (HIV) infection is a worldwide public-health priority. We evaluated the population effects of potential preventive and therapeutic vaccines in early- and late-stage epidemics in a population of homosexual men. Methods: We used an epidemic model that simulated the course of the epidemic for a population designed to reflect that of homosexual men in San Francisco, California. We evaluated vaccine programs by the number of cases of HIV averted, the effect on the prevalence of HIV, and by the gain in quality-adjusted life years (QALYs) for the total population. Findings: A preventive vaccine prevented 3877 cases of HIV infection during a 20-year period, reduced the projected prevalence of HIV infection from 12% to 7% in a late-stage epidemic, and gained 15,908 QALYs. A therapeutic-vaccine that did not affect the infectivity of vaccine recipients increased the number of cases of HIV infection by 210, resulted in a slight increase in the prevalence of HIV infection from 12% to 15% in a late-stage epidemic, and gained 8854 QALYs. If therapeutic vaccines reduced infectivity, their use could produce net gains of quality-adjusted life years in the population that were identical to gains from the use of preventive vaccines. In an early-stage epidemic, the advantage of a preventive-vaccine program relative to a therapeutic vaccine program was markedly enhanced. Interpretation: Both preventive- and therapeutic-vaccine programs provided substantial benefit, but their relative merit depended on which outcome measures we assessed. Evaluation of HIV vaccine programs based solely on cases averted, or on prevalence of HIV in the population, underestimates the benefit associated with therapeutic-vaccine programs. The effect of a therapeutic HIV vaccine on the epidemic outcomes depended markedly on whether the therapeutic vaccine reduced the infectivity of the vaccine recipient. Field vaccine trials should evaluate correlates of infectivity, such as HIV viral load. HIV vaccine implementations trategies should be tailored to the dynamics of the epidemic in specific populations.