Background: The effect of HIV pre-exposure prophylaxis (PrEP) depends on uptake, adherence, and sexual practices. We aimed to assess these factors in a cohort of HIV-negative people at risk of infection. Methods: In our cohort study, men and transgender women who have sex with men previously enrolled in PrEP trials (ATN 082, iPrEx, and US Safety Study) were enrolled in a 72 week open-label extension. We measured drug concentrations in plasma and dried blood spots in seroconverters and a random sample of seronegative participants. We assessed PrEP uptake, adherence, sexual practices, and HIV incidence. Statistical methods included Poisson models, comparison of proportions, and generalised estimating equations. Findings: We enrolled 1603 HIV-negative people, of whom 1225 (76%) received PrEP. Uptake was higher among those reporting condomless receptive anal intercourse (416/519 [81%] vs 809/1084 [75%], p=0·003) and having serological evidence of herpes (612/791 [77%] vs 613/812 [75%] p=0·03). Of those receiving PrEP, HIV incidence was 1·8 infections per 100 person-years, compared with 2·6 infections per 100 person-years in those who concurrently did not choose PrEP (HR 0·51, 95% CI 0·26-1·01, adjusted for sexual behaviours), and 3·9 infections per 100 person-years in the placebo group of the previous randomised phase (HR 0·49, 95% CI 0·31-0·77). Among those receiving PrEP, HIV incidence was 4·7 infections per 100 person-years if drug was not detected in dried blood spots, 2·3 infections per 100 person-years if drug concentrations suggested use of fewer than two tablets per week, 0·6 per 100 person-years for use of two to three tablets per week, and 0·0 per 100 person-years for use of four or more tablets per week (p<0·0001). PrEP drug concentrations were higher among people of older age, with more schooling, who reported non-condom receptive anal intercourse, who had more sexual partners, and who had a history of syphilis or herpes. Interpretation: PrEP uptake was high when made available free of charge by experienced providers. The effect of PrEP is increased by greater uptake and adherence during periods of higher risk. Drug concentrations in dried blood spots are strongly correlated with protective benefit.