Background: Metastatic castration-resistant prostate cancers are enriched for DNA repair gene defects (DRDs) that can be susceptible to synthetic lethality through inhibition of PARP proteins. We evaluated the anti-tumour activity and safety of the PARP inhibitor niraparib in patients with metastatic castration-resistant prostate cancers and DRDs who progressed on previous treatment with an androgen signalling inhibitor and a taxane. Methods: In this multicentre, open-label, single-arm, phase 2 study, patients aged at least 18 years with histologically confirmed metastatic castration-resistant prostate cancer (mixed histology accepted, with the exception of the small cell pure phenotype) and DRDs (assessed in blood, tumour tissue, or saliva), with progression on a previous next-generation androgen signalling inhibitor and a taxane per Response Evaluation Criteria in Solid Tumors 1.1 or Prostate Cancer Working Group 3 criteria and an Eastern Cooperative Oncology Group performance status of 0–2, were eligible. Enrolled patients received niraparib 300 mg orally once daily until treatment discontinuation, death, or study termination. For the final study analysis, all patients who received at least one dose of study drug were included in the safety analysis population; patients with germline pathogenic or somatic biallelic pathogenic alterations in BRCA1 or BRCA2 (BRCA cohort) or biallelic alterations in other prespecified DRDs (non-BRCA cohort) were included in the efficacy analysis population. The primary endpoint was objective response rate in patients with BRCA alterations and measurable disease (measurable BRCA cohort). This study is registered with ClinicalTrials.gov, NCT02854436. Findings: Between Sept 28, 2016, and June 26, 2020, 289 patients were enrolled, of whom 182 (63%) had received three or more systemic therapies for prostate cancer. 223 (77%) of 289 patients were included in the overall efficacy analysis population, which included BRCA (n=142) and non-BRCA (n=81) cohorts. At final analysis, with a median follow-up of 10·0 months (IQR 6·6–13·3), the objective response rate in the measurable BRCA cohort (n=76) was 34·2% (95% CI 23·7–46·0). In the safety analysis population, the most common treatment-emergent adverse events of any grade were nausea (169 [58%] of 289), anaemia (156 [54%]), and vomiting (111 [38%]); the most common grade 3 or worse events were haematological (anaemia in 95 [33%] of 289; thrombocytopenia in 47 [16%]; and neutropenia in 28 [10%]). Of 134 (46%) of 289 patients with at least one serious treatment-emergent adverse event, the most common were also haematological (thrombocytopenia in 17 [6%] and anaemia in 13 [4%]). Two adverse events with fatal outcome (one patient with urosepsis in the BRCA cohort and one patient with sepsis in the non-BRCA cohort) were deemed possibly related to niraparib treatment. Interpretation: Niraparib is tolerable and shows anti-tumour activity in heavily pretreated patients with metastatic castration-resistant prostate cancer and DRDs, particularly in those with BRCA alterations. Funding: Janssen Research & Development.