Background: Timely diagnosis of infant HIV infection is essential for antiretroviral therapy (ART) initiation. In a randomized controlled trial, we found the Texting Improves Testing (TextIT) intervention (a theory-based text messaging system) to be efficacious for improving infant HIV testing rates and maternal retention in prevention of mother-to-child HIV transmission (PMTCT) programs. Using an implementation science approach, we aimed to evaluate real-world effectiveness of the intervention. Methods and findings: In a pragmatic, cluster-randomized, stepped-wedge trial with 2 time periods of observation, we randomly allocated 10 clinics to begin implementing the intervention immediately and 10 clinics to begin implementing 6 months later. To approximate real-world conditions, inclusion criteria were broad. Women at clinics implementing the intervention received up to 14 text messages during pregnancy and after delivery and had the option to respond to text messages, call, or send inquiry text messages to a designated clinic phone. The primary outcomes were infant HIV testing and maternal retention in care during the first 8 weeks after delivery. We used modified Poisson regression with robust variance estimation to estimate the relative risk and 95% confidence intervals (CIs). Generalized estimating equations were applied on individual-level data to account for clustering by site. Between February 2015 and December 2016, 4,681 women were assessed for study participation, and 2,515 were included. Participant characteristics at enrollment did not differ by study arm. Overall median age was 27 years (interquartile range [IQR] 23-30), median gestational age was 30 weeks (IQR 28-34), 99% were receiving ART, and 87% who enrolled during intervention phases owned a phone. Of 2,326 infants analyzed, 1,466 of 1,613 (90.9%) in the intervention group and 609 of 713 (85.4%) in the control group met the primary outcome of HIV virologic testing performed before 8 weeks after birth (adjusted relative risk [aRR] 1.03; 95% CI 0.97-1.10; P = 0.3). Of 2,472 women analyzed, 1,548 of 1,725 (90%) in the intervention group and 571 of 747 (76%) in the control group met the primary outcome of retention in care during the first 8 weeks after delivery (aRR 1.12; 95% CI 0.97-1.30; P = 0.1). This study had two main limitations. Staff at all facilities were aware of ongoing observation, which may have contributed to increased rates of infant HIV testing and maternal retention in care at both intervention and control facilities, and programmatic initiatives to improve maternal and infant retention in care were ongoing at all facilities at the time of this study, which likely limited the ability to demonstrate effectiveness of the trial intervention. Conclusions: In this study, a larger proportion of infants in the intervention group received HIV testing compared with the control group, but the difference was small and not statistically significant. There was also a nonsignificant increase in maternal postpartum retention in the intervention periods. Despite the lack of a significant effect of the intervention, key lessons emerged, both for strengthening PMTCT and for implementation research in general. Perhaps most important, improving the implementation of usual care may have been sufficient to substantially improve infant HIV testing rates.