Background: Safe and effective long-acting injectable agents for preexposure prophylaxis (PrEP) for human immunodeficiency virus (HIV) infection are needed to increase the options for preventing HIV infection. Methods: We conducted a randomized, double-blind, double-dummy, noninferiority trial to compare long-acting injectable cabotegravir (CAB-LA, an integrase strand-transfer inhibitor [INSTI]) at a dose of 600 mg, given intramuscularly every 8 weeks, with daily oral tenofovir disoproxil fumarate-emtricitabine (TDF-FTC) for the prevention of HIV infection in at-risk cisgender men who have sex with men (MSM) and in at-risk transgender women who have sex with men. Participants were randomly assigned (1:1) to receive one of the two regimens and were followed for 153 weeks. HIV testing and safety evaluations were performed. The primary end point was incident HIV infection. Results: The intention-to-treat population included 4566 participants who underwent randomization; 570 (12.5%) identified as transgender women, and the median age was 26 years (interquartile range, 22 to 32). The trial was stopped early for efficacy on review of the results of the first preplanned interim end-point analysis. Among 1698 participants from the United States, 845 (49.8%) identified as Black. Incident HIV infection occurred in 52 participants: 13 in the cabotegravir group (incidence, 0.41 per 100 person-years) and 39 in the TDF-FTC group (incidence, 1.22 per 100 person-years) (hazard ratio, 0.34; 95% confidence interval, 0.18 to 0.62). The effect was consistent across prespecified subgroups. Injection-site reactions were reported in 81.4% of the participants in the cabotegravir group and in 31.3% of those in the TDF-FTC group. In the participants in whom HIV infection was diagnosed after exposure to CAB-LA, INSTI resistance and delays in the detection of HIV infection were noted. No safety concerns were identified. Conclusions: CAB-LA was superior to daily oral TDF-FTC in preventing HIV infection among MSM and transgender women. Strategies are needed to prevent INSTI resistance in cases of CAB-LA PrEP failure.