Community mobilisation, engaging communities in a process to collectively enact change, could improve HIV testing and care engagement. In South Africa, current rates fall below those needed for epidemic control. We assessed whether community mobilisation increased HIV testing, linkage to care, and retention in care over time in intervention relative to control communities. We conducted a cluster-randomised controlled trial in villages in the Agincourt sub-district of the rural Mpumalanga Province in South Africa. 15 villages were randomly assigned to either a community mobilisation intervention engaging residents to address social barriers to HIV testing and treatment (intervention arm) or to a control arm using balanced randomisation. Villages were eligible if they had been fully enumerated in 2014, had not been included in previous mobilisation activities, and included over 500 permanent adult residents aged 18-49 years. Primary outcomes included quarterly rates of HIV testing, linkage to care, and retention in care documented from health facility records among residents of the intervention and control communities over the 3-year study period. Intention-to-treat analyses employed generalised estimating equations stratified by sex. This trial is registered with ClinicalTrials.gov, NCT02197793. Between Aug 1, 2015, and July 31, 2018, residents in eight intervention communities (n=20 544 residents) and seven control communities (n=17 848) contributed data; 92 residents contributed to both arms. Among men, HIV testing increased quarterly by 12·1% (relative change [RC] 1·121, 95% CI 1·099 to 1·143, p<0·0001) in the intervention communities and 9·5% (1·095, 1·075 to 1·114, p=0·011) in the control communities; although increases in testing were greater in the intervention villages, differences did not reach significance (exponentiated interaction coefficient 1·024, 95% CI 0·997 to 1·052, p=0·078). Among women, HIV testing increased quarterly by 10·6% (RC 1·106, 95% CI 1·097 to 1·114, p<0·0001) in the intervention communities and 9·3% (1·093, 1·084 to 1·102, p=0·053) in the control communities; increases were greater in intervention communities (exponentiated interaction coefficient 1·012, 95% CI 1·001 to 1·023, p=0·043). Quarterly linkage increased significantly among women in the intervention communities (RC 1·013, 95% CI 1·002 to 1·023, p=0·018) only. Quarterly linkage fell among men in both arms, but decreased significantly among men in the control communities (0·977, 0·954 to 1·002, p=0·043). Quarterly retention fell among women in both arms; however, reductions were tempered among women in the intervention communities (exponentiated interaction coefficient 1·003, 95% CI <1·000 to 1·006, p=0·062). Retention fell significantly among men in both arms with difference in rates of decline. Community mobilisation was associated with modest improvements in select trial outcomes. The sum of these incremental, quarterly improvements achieved by addressing social barriers to HIV care engagement can impact epidemic control. However, achieving optimal impacts will probably require integrated efforts addressing both social barriers through community mobilisation and provision of improved service delivery. US National Institutes of Health, National Institute of Mental Health, and United States President's Emergency Plan for AIDS Relief through Right to Care and Project SOAR.