Background: Avahan, the India AIDS initiative of the Bill & Melinda Gates Foundation, was a large-scale, targeted HIV prevention intervention. We aimed to assess its overall effectiveness by estimating the number and proportion of HIV infections averted across Avahan districts, following the causal pathway of the intervention. Methods: We created a mathematical model of HIV transmission in high-risk groups and the general population using data from serial cross-sectional surveys (integrated behavioural and biological assessments, IBBAs) within a Bayesian framework, which we used to reproduce HIV prevalence trends in female sex workers and their clients, men who have sex with men, and the general population in 24 South Indian districts over the first 4 years (2004-07 or 2005-08 dependent on the district) and the full 10 years (2004-13) of the Avahan programme. We tested whether these prevalence trends were more consistent with self-reported increases in consistent condom use after the implementation of Avahan or with a counterfactual (assuming consistent condom use increased at slower, pre-Avahan rates) using a Bayes factor, which gave a measure of the strength of evidence for the effectiveness estimates. Using regression analysis, we extrapolated the prevention effect in the districts covered by IBBAs to all 69 Avahan districts. Findings: In 13 of 24 IBBA districts, modelling suggested medium to strong evidence for the large self-reported increase in consistent condom use since Avahan implementation. In the remaining 11 IBBA districts, the evidence was weaker, with consistent condom use generally already high before Avahan began. Roughly 32 700 HIV infections (95% credibility interval 17 900-61 600) were averted over the first 4 years of the programme in the IBBA districts with moderate to strong evidence. Addition of the districts with weaker evidence increased this total to 62 800 (32 000-118 000) averted infections, and extrapolation suggested that 202 000 (98 300-407 000) infections were averted across all 69 Avahan districts in South India, increasing to 606 000 (290 000-1 193 000) over 10 years. Over the first 4 years of the programme 42% of HIV infections were averted, and over 10 years 57% were averted. Interpretation: This is the first assessment of Avahan to account for the causal pathway of the intervention, that of changing risk behaviours in female sex workers and high-risk men who have sex with men to avert HIV infections in these groups and the general population. The findings suggest that substantial preventive effects can be achieved by targeted behavioural HIV prevention initiatives.