Few effective community-based interventions exist to increase HIV testing and uptake of antiretroviral therapy (ART) in pregnant women in hard-to-reach resource-limited settings. We assessed whether delivery of an intervention through churches, the Healthy Beginning Initiative, would increase uptake of HIV testing in pregnant women compared with standard health facility referral. In this cluster randomised trial, we enrolled self-identified pregnant women aged 18 years and older who attended churches in southeast Nigeria. We randomised churches (clusters) to intervention or control groups, stratified by mean annual number of infant baptisms (<80 vs ≥80). The Healthy Beginning Initiative intervention included health education and on-site laboratory testing implemented during baby showers in intervention group churches, whereas participants in control group churches were referred to health facilities as standard. Participants and investigators were aware of church allocation. The primary outcome was confirmed HIV testing. This trial is registered with ClinicalTrials.gov, identifier number NCT 01795261. Between Jan 20, 2013, and Aug 31, 2014, we enrolled 3002 participants at 40 churches (20 per group). 1309 (79%) of 1647 women attended antenatal care in the intervention group compared with 1080 (80%) of 1355 in the control group. 1514 women (92%) in the intervention group had an HIV test compared with 740 (55%) controls (adjusted odds ratio 11·2, 95% CI 8·77-14·25; p<0·0001). Culturally adapted, community-based programmes such as the Healthy Beginning Initiative can be effective in increasing HIV screening in pregnant women in resource-limited settings. US National Institutes of Health and US President's Emergency Plan for AIDS Relief.