Background: Universal testing and treatment (UTT) for all people living with HIV has only been assessed under experimental conditions in cluster-randomised trials. The public health effectiveness of UTT policies on the HIV care cascade under real-world conditions is not known. We assessed the real-world effectiveness of universal HIV treatment policies that were implemented in Zambia on Jan 1, 2017. Methods: We used data from Zambia's routine electronic health record system to analyse antiretroviral therapy (ART)-naive adults who newly enrolled in HIV care up to 1 year before and after the implementation of universal treatment (ie, Jan 1, 2016, to Jan 1, 2018) at 117 clinics supported by the Centre for Infectious Disease Research in Zambia. We used a regression discontinuity design to estimate the effects of implementing UTT on same-day ART initiation, ART initiation within 1 month, and retention on ART at 12 months (defined as clinic attendance 9–15 months after enrolment and at least 6 months on ART), under the assumption that patients presenting immediately before and after UTT implementation were balanced on both measured and unmeasured characteristics. We did an instrumental variable analysis to estimate the effect of same-day ART initiation under routine conditions on 12-month retention on ART. Findings: 65 673 newly enrolled patients with HIV (40 858 [62·2%] female, median age 32 years [IQR 26–39], median CD4 count 287 cells per μL [IQR 147–466]) were eligible for inclusion in the analyses; 31 145 enrolled before implementation of UTT, and 34 528 enrolled after UTT. Implementation of universal treatment increased same-day ART initiation from 41·7% to 74·8% (risk difference [RD] 33·1%, 95% CI 30·5–35·7), ART initiation by 1 month from 69·6% to 87·0% (RD 17·4%, 15·5–19·3), and 12-month retention on ART from 56·2% to 63·3% (RD 7·1%, 4·3–9·9). ART initiation rates became more uniform across patient subgroups after implementation of universal treatment, but heterogeneity in 12-month retention on ART between subgroups was unchanged. Instrumental variable analyses indicated that same-day ART initiation in routine settings led to a 15·8% increase (95% CI 12·1–19·5) in 12-month retention on ART. Interpretation: UTT policies implemented in Zambia increased the rapidity and uptake of ART, as well as retention on ART at 12 months, although overall retention on ART remained suboptimal. UTT policies reduced disparities in treatment initiation, but not 12-month retention on ART. Natural experiments reveal both the anticipated and unanticipated effects of real-world implementation and indicate the need for new strategies leveraging the short-term effects of UTT to cultivate long-term treatment success. Funding: National Institutes of Health.