Background: HIV pre-exposure prophylaxis (PrEP), the use of antiretroviral drugs by uninfected individuals to prevent HIV infection, has demonstrated effectiveness in preventing acquisition in a high-risk population of men who have sex with men (MSM). Consequently, there is a need to understand if and how PrEP can be used cost-effectively to prevent HIV infection in such populations. Methods and Findings: We developed a mathematical model representing the HIV epidemic among MSM and transwomen (male-to-female transgender individuals) in Lima, Peru, as a test case. PrEP effectiveness in the model is assumed to result from the combination of a "conditional efficacy" parameter and an adherence parameter. Annual operating costs from a health provider perspective were based on the US Centers for Disease Control and Prevention interim guidelines for PrEP use. The model was used to investigate the population-level impact, cost, and cost-effectiveness of PrEP under a range of implementation scenarios. The epidemiological impact of PrEP is largely driven by programme characteristics. For a modest PrEP coverage of 5%, over 8% of infections could be averted in a programme prioritising those at higher risk and attaining the adherence levels of the Pre-Exposure Prophylaxis Initiative study. Across all scenarios, the highest estimated cost per disability-adjusted life year averted (uniform strategy for a coverage level of 20%, US$1,036-US$4,254) is below the World Health Organization recommended threshold for cost-effective interventions, while only certain optimistic scenarios (low coverage of 5% and some or high prioritisation) are likely to be cost-effective using the World Bank threshold. The impact of PrEP is reduced if those on PrEP decrease condom use, but only extreme behaviour changes among non-adherers (over 80% reduction in condom use) and a low PrEP conditional efficacy (40%) would adversely impact the epidemic. However, PrEP will not arrest HIV transmission in isolation because of its incomplete effectiveness and dependence on adherence, and because the high cost of programmes limits the coverage levels that could potentially be attained. Conclusions: A strategic PrEP intervention could be a cost-effective addition to existing HIV prevention strategies for MSM populations. However, despite being cost-effective, a substantial expenditure would be required to generate significant reductions in incidence. Please see later in the article for the Editors' Summary. Gomez et al.