The UNAIDS estimate of vertical HIV transmission in Tanzania is high (11%), despite 84% uptake of antiretroviral therapy (ART) among pregnant women with HIV. We aimed to evaluate vertical transmission and its determinants by 18 months post partum among women on lifelong ART in routine health-care settings in Tanzania. We conducted a prospective cohort study in 226 health facitilies across Dar-es-Salaam, Tanzania. Eligible participants were pregnant women of any age with HIV, and later their infants, who enrolled in routine health-care services for the prevention of vertical transmission. We prospectively followed up mother-infant pairs at routine monthly visits until 18 months post partum and extracted data from the care and treatment clinic (CTC2) database, a national electronic database that stores patient-level HIV care and treatment clinic data. The primary outcome was time from birth to HIV diagnosis, defined as a positive infant HIV DNA PCR or antibody test from age 18 months. We used the Kaplan-Meier method to estimate cumulative risk of vertical transmission by 18 months post partum and Cox proportional hazards regression with shared frailties to account for potential clustering in health facilities to evaluate predictors of transmission. Between Jan 1, 2015, and Dec 31, 2017, 22 930 pregnant women with HIV (median age 30 years, IQR 25-34) enrolled on a care programme. After excluding 9140 (39·9%) women and 539 (2·4%) infants with missing outcome data, 13 251 (59·0%) mother-infant pairs were analysed, of whom 6072 (45·8%) women were already on ART before pregnancy. By 18 months post partum, 159 (1·2%) of 13 251 infants were diagnosed with HIV, equivalent to a risk of vertical transmission of 1·4% (95% CI 1·2-1·6). In the complete case analysis, the rates of vertical transmission were higher among women who enrolled in the third trimester of pregnancy than among those who enrolled in the first trimester (adjusted hazard ratio 3·01, 95% CI 1·59-5·70; p=0·0003), among women with advanced HIV disease than among those with early-stage disease (1·89, 1·22-2·93; p=0·0046), and among women who were on a second-line ART regimen than among those on a first-line regimen (3·58, 1·08-11·82; p=0·037). By contrast, the rate of vertical transmission was lower among women who were already on ART at enrolment than among those starting ART at enrolment (0·39, 0·25-0·60; p<0·0001) as well as among women in high-volume clinics than among those in low-volume clinics (0·46 (0·24-0·90; p<0·0097). Provision of ART for life (WHO's option B+ recommendation) has reduced the risk of vertical transmission to less than 2% among pregnant women with HIV in routine care settings in urban Tanzania. There is still a need to improve timely HIV diagnosis and ART uptake, and to optimise follow-up for the prevention of vertical transmission and the uptake of infant HIV testing. Swedish International Development Cooperation Agency.