Background Prosthetic joint infection is a devastating complication of knee replacement. The risk of developing a prosthetic joint infection is affected by patient, surgical, and health-care system factors. Existing evidence is limited by heterogeneity in populations studied, short follow-up, inadequate power, and does not differentiate early prosthetic joint infection, most likely related to the intervention, from late infection, more likely to occur due to haematogenous bacterial spread. We aimed to assess the overall and time-specific associations of these factors with the risk of revision due to prosthetic joint infection following primary knee replacement. Methods In this cohort study, we analysed primary knee replacements done between 2003 and 2013 in England and Wales and the procedures subsequently revised for prosthetic joint infection between 2003 and 2014. Data were obtained from the National Joint Registry linked to the Hospital Episode Statistics data in England and the Patient Episode Database for Wales. Each primary replacement was followed for a minimum of 12 months until the end of the observation period (Dec 31, 2014) or until the date of revision for prosthetic joint infection, revision for another indication, or death (whichever occurred first). We analysed the data using Poisson and piecewise exponential multilevel models to assess the associations between patient, surgical, and health-care system factors and risk of revision for prosthetic joint infection. Findings Of 679 010 primary knee replacements done between 2003 and 2013 in England and Wales, 3659 were subsequently revised for an indication of prosthetic joint infection between 2003 and 2014, after a median follow-up of 4•6 years (IQR 2•6-6•9). Male sex (rate ratio [RR] for male vs female patients 1•8 [95% CI 1•7-2•0]), younger age (RR for age ≥80 years vs <60 years 0•5 [0•4-0•6]), higher American Society of Anaesthesiologists [ASA] grade (RR for ASA grade 3-5 vs 1, 1•8 [1•6-2•1]), elevated body-mass index (BMI; RR for BMI ≥30 kg/m² vs <25 kg/m² 1•5 [1•3-1•6]), chronic pulmonary disease (RR 1•2 [1•1-1•3]), diabetes (RR 1•4 [1•2-1•5]), liver disease (RR 2•2 [1•6-2•9]), connective tissue and rheumatic diseases (RR 1•5 [1•3-1•7]), peripheral vascular disease (RR 1•4 [1•1-1•7]), surgery for trauma (RR 1•9 [1•4-2•6]), previous septic arthritis (RR 4•9 [2•7-7•6]) or inflammatory arthropathy (RR 1•4 [1•2-1•7]), operation under general anaesthesia (RR 1•1 [1•0-1•2]), requirement for tibial bone graft (RR 2•0 [1•3-2•7]), use of posterior stabilised fixed bearing prostheses (RR for posterior stabilised fixed bearing prostheses vs unconstrained fixed bearing prostheses 1•4 [1•3-1•5]) or constrained condylar prostheses (3•5 [2•5-4•7]) were associated with a higher risk of revision for prosthetic joint infection. However, uncemented total, patellofemoral, or unicondylar knee replacement (RR for uncemented vs cemented total knee replacement 0•7 [95% CI 0•6-0•8], RR for patellofemoral vs cemented total knee replacement 0•3 [0•2-0•5], and RR for unic...