Young survivors of cancer are at increased risk for cancers that are related to human papillomavirus (HPV), primarily caused by oncogenic HPV types 16 and 18. We aimed to examine the immunogenicity and safety of the three-dose series of HPV vaccine in young survivors of cancer. We conducted an investigator-initiated, phase 2, single-arm, open-label, non-inferiority trial at five National Cancer Institute-designated comprehensive cancer centres in the USA. Eligible participants were survivors of cancer who were HPV vaccine-naive, were aged 9-26 years, in remission, and had completed cancer therapy between 1 and 5 years previously. Participants received three intramuscular doses of either quadrivalent HPV vaccine (HPV4; enrolments on or before March 1, 2016) or nonavalent HPV vaccine (HPV9; enrolments after March 1, 2016) over 6 months (on day 1, at month 2, and at month 6). We also obtained data from published clinical trials assessing safety and immunogenicity of HPV4 and HPV9 in 9-26-year-olds from the general population, as a comparator group. The primary endpoint was antibody response against HPV types 16 and 18 at month 7 in the per-protocol population. A response was deemed non-inferior if the lower bound of the multiplicity-adjusted 95% CI was greater than 0·5 for the ratio of anti-HPV-16 and anti-HPV-18 geometric mean titres (GMTs) in survivors of cancer versus the general population. Responses were examined separately in male and female participants by age group (ie, 9-15 years and 16-26 years). Safety was assessed in all participants who received at least one vaccine dose and for whom safety data were available. This study is registered with ClinicalTrials.gov, NCT01492582. This trial is now completed. Between Feb 18, 2013, and June 22, 2018, we enrolled 453 survivors of cancer, of whom 436 received one or more vaccine doses: 203 (47%) participants had survived leukaemia, 185 (42%) were female, and 280 (64%) were non-Hispanic white. Mean age at first dose was 15·6 years (SD 4·6). 378 (83%) of 453 participants had evaluable immunogenicity data; main reasons for exclusion from per-protocol analysis were to loss to follow-up, patient reasons, and medical reasons. Data were also obtained from 26 486 general population controls. The ratio of mean GMT for anti-HPV types 16 and 18 in survivors of cancer versus the general population was more than 1 for all subgroups (ie, aged 9-15 years, aged 16-26 years, male, and female groups) in both vaccine cohorts (ranging from 1·64 [95% CI 1·12-2·18] for anti-HPV type 16 in female participants aged 9-15 years who received HPV9, to 4·77 [2·48-7·18] for anti-HPV type 18 in male participants aged 16-26 years who received HPV4). Non-inferiority criteria were met within each age and sex subgroup, except against HPV type 18 in female participants aged 16-26 years receiving HPV9 (4·30 [0·00-9·05]). Adverse events were reported by 237 (54%) of 435 participants; injection site pain was most common (174 [40%] participants). One serious adverse event (ie, erythema nodosum) was possibly related to vaccine (HPV9; 16-26 year female cohort). Immunogenicity and safety of HPV vaccine three-dose series in survivors of cancer is similar to that in the general population, providing evidence for use in this clinically vulnerable population. US National Cancer Institute, Merck, Sharp & Dohme, and American Lebanese Syrian Associated Charities.