BACKGROUND: WHO recommends that men who have sex with men (MSM) receive gonorrhoea and chlamydia testing, but many evidence-based preventive services are unaffordable. The pay-it-forward strategy offers an individual a gift (eg, a test for sexually transmitted diseases) and then asks whether they would like to give a gift (eg, a future test) to another person. This study examined the effectiveness of a pay-it-forward programme to increase gonorrhoea and chlamydia testing among MSM in China. METHODS: We did a randomised controlled superiority trial at three HIV testing sites run by MSM community-based organisations in Guangzhou and Beijing, China. We included MSM aged 16 years or older who were seeking HIV testing and met indications for gonorrhoea and chlamydia testing. Restricted randomisation was done using computer-generated permuted blocks. 30 groups were randomised into three arms (1:1:1): a pay-it-forward arm in which men were offered free gonorrhoea and chlamydia testing and then asked whether they would like to donate for testing of prospective participants, a pay-what-you-want arm in which men were offered free testing and given the option to pay any desired amount for the test, and a standard-of-care arm in which testing was offered at yen150 (US$22). There was no masking to arm assignment. The primary outcome was gonorrhoea and chlamydia test uptake ascertained by administrative records. We used generalised estimating equations to estimate intervention effects with one-sided 95% CIs and a prespecified superiority margin of 20%. The trial is registered with ClinicalTrials.gov, NCT03741725. FINDINGS: Between Dec 8, 2018, and Jan 19, 2019, 301 men were recruited and included in the analysis. 101 were randomly assigned to the pay-it-forward group, 100 to the pay-what-you- want group, and 100 to the standard-of-care group. Test uptake for gonorrhoea and chlamydia was 56% (57 of 101 participants) in the pay-it- forward arm, 46% (46 of 100 participants) in the pay-what-you-want arm, and 18% (18 of 100 participants) in the standard-of-care arm. The estimated difference in test uptake between the pay-it-forward and standard-of-care group was 38.4% (95% CI lower bound 28.4%). Among men in the pay-it-forward arm, 54 of 57 (95%) chose to donate to support testing for others. INTERPRETATION: The pay-it-forward strategy can increase gonorrhoea and chlamydia testing uptake among Chinese MSM and could be a useful tool for scaling up preventive services that carry a mandatory fee. FUNDING: US National Institute of Health; Special Programme for Research and Training in Tropical Diseases, sponsored by UNICEF, UNDP, World Bank, and WHO; the National Key Research and Development Program of China; Doris Duke Charitable Foundation; and Social Entrepreneurship to Spur Health.