Men who have sex with men (MSM) who practice chemsex have a higher likelihood of engaging in risky sexual behaviors and higher rates of HIV infection and other sexually transmitted infections (STIs) than those who do not. This trial aimed to evaluate the effectiveness of a web-based intervention in reducing the sexual harms of chemsex among MSM. The study was a 2-arm, assessor-blinded, randomized, parallel-group trial with a 3-month follow-up period. The study was conducted in the year 2021 in Hong Kong. Underpinned by the theory of planned behaviors and a harm reduction approach, the intervention consisted of interactive components and knowledge-based information about chemsex. Participants in the control group received brief information and content about sexual violence. The primary outcome was self-efficacy in refusing risky sexual behaviors and chemsex, as measured by the Condom Self-Efficacy Scale (CSES), Self-Efficacy for Sexual Safety (SESS) instrument, and Drug Avoidance Self-Efficacy Scale (DASES). The secondary outcomes included intentions to have chemsex, actual engagement in chemsex, HIV and other STI testing, and condom use in the last 3 months. All outcomes were self-reported. An online structured questionnaire was used to collect data. In total, 316 MSM enrolled in the study. The intervention group demonstrated a significantly larger improvement in condom-use self-efficacy (as measured by CSES scores; time-by-group interaction: β=4.52, 95% CI 2.03-7.02; P<.001), self-efficacy for sexual safety (as measured by SESS scores; time-by-group interaction: β=2.11, 95% CI 0.66-3.56; P=.004), and drug avoidance self-efficacy (as measured by DASES scores; time-by-group interaction: β=6.98, 95% CI 1.75-12.22; P=.009). Regarding the secondary outcomes, participants in the intervention group demonstrated a significantly larger reduction in the likelihood of having engaged in chemsex in the last 3 months (time-by-group interaction: odds ratio [OR]=0.23, 95% CI 0.10-0.53; P=.001) and likelihood of having had the intention to engage in chemsex in the last 3 months (time-by-group interaction: OR=0.37, 95% CI 0.18-0.78; P=.009). Participants in the intervention group also showed a significantly larger increase in the likelihood of having undergone HIV testing in the last 3 months (time-by-group interaction: OR=3.08, 95% CI 1.72-5.54; P<.001). This study suggests that a web-based intervention with a harm reduction approach can enhance the self-efficacy of MSM in refusing risky sexual behaviors and chemsex and improve the uptake of HIV testing. We also provide initial evidence that such interventions can reduce both the intention of MSM to engage in chemsex and their actual engagement in chemsex. ISRCTN Registry ISRCTN20134522; https://www.isrctn.com/ISRCTN20134522. RR2-10.1186/s12889-021-10742-8.