Human papillomavirus (HPV)-based cervical screening is a globally recommended public health policy. Randomised clinical trials find superior performance of primary HPV-based screening compared with cytology for preventing cervical cancer. However, additional evidence from real-world public health policies is needed. In preplanned secondary analysis of a randomised health-care policy trial in Sweden we aimed to evaluate which policy provided better protection against invasive cervical cancer, after two full rounds of screening. The organised cervical screening programme in the capital region of Sweden invited all women aged 30-64 years and eligible for screening to a randomised health-care policy trial of HPV-based versus cytology-based screening. During 2014-16, 395 725 eligible women were randomly assigned (non-concealed) to either policy and the invasive cervical cancer incidences over 8 years of follow-up were compared. Intention-to-screen analyses included all invited women and per-protocol analyses the women that attended baseline screening according to protocol. This trial is registered with ClinicalTrials.gov, NCT01511328. Women invited to HPV-based cervical screening had a 17% lower invasive cervical cancer risk compared with women invited to cytology (hazard ratio [HR] 0·83, 95% CI 0·70-0·98). Women participating in HPV-based screening had a 28% lower invasive cervical cancer risk compared with women participating with cytology (HR 0·72, 95% CI 0·54-0·95). Adverse events were a higher number of referrals to colposcopy with biopsy in the HPV policy (15 832 [7·5%] of 212 199 in intention to screen analyses and 9968 [9·0%] of 110 176 per protocol at baseline) than in the cytology policy (12 650 [6·9%] of 183 120 in intention to screen analyses, and 7179 [7·9%] of 90 821 per protocol at baseline). Women who were HPV-negative at baseline had invasive cervical cancer risks of 1·3 (95% CI 0·6-2·4) per 100 000 person-years, whereas the risk for women with normal cytology was 9·1 (6·7-11·8) per 100 000 person-years. HPV-positive women with negative cytology triage had invasive cervical cancer risks of 79·2 per 100 000 person-years and HPV 16 or HPV 18-positive women with negative cytology triage had risks of 318·2 per 100 000 person-years. This randomised policy trial found HPV-based screening to be superior for preventing invasive cervical cancer in the real-world setting. A single baseline HPV-negative test was associated with a very low invasive cervical cancer risk after 8 years. However, HPV positivity with negative cytology triage was associated with high invasive cervical cancer risks. Region Stockholm, Swedish Cancer Society, and European Union Horizon 2020.