Background: People who inject drugs (PWID) experience a high prevalence of incarceration and might be at high risk of HIV and hepatitis C virus (HCV) infection during or after incarceration. We aimed to assess whether incarceration history elevates HIV or HCV acquisition risk among PWID. Methods: In this systematic review and meta-analysis, we searched MEDLINE, Embase, and PsycINFO databases for studies in any language published from Jan 1, 2000 until June 13, 2017 assessing HIV or HCV incidence among PWID. We included studies that measured HIV or HCV incidence among community-recruited PWID. We included only studies reporting original results and excluded studies that evaluated incident infections by self-report. We contacted authors of cohort studies that met the inclusion or exclusion criteria, but that did not report on the outcomes of interest, to request data. We extracted and pooled data from the included studies using random-effects meta-analyses to quantify the associations between recent (past 3, 6, or 12 months or since last follow-up) or past incarceration and HIV or HCV acquisition (primary infection or reinfection) risk among PWID. We assessed the risk of bias of included studies using the Newcastle-Ottawa Scale. Between-study heterogeneity was evaluated using the I2 statistic and the P-value for heterogeneity. Findings: We included published results from 20 studies and unpublished results from 21 studies. These studies originated from Australasia, western and eastern Europe, North and Latin America, and east and southeast Asia. Recent incarceration was associated with an 81% (relative risk [RR] 1·81, 95% CI 1·40–2·34) increase in HIV acquisition risk, with moderate heterogeneity between studies (I2=63·5%; p=0·001), and a 62% (RR 1·62, 95% CI 1·28–2·05) increase in HCV acquisition risk, also with moderate heterogeneity between studies (I2=57·3%; p=0·002). Past incarceration was associated with a 25% increase in HIV (RR 1·25, 95% CI 0·94–1·65) and a 21% increase in HCV (1·21, 1·02–1·43) acquisition risk. Interpretation: Incarceration is associated with substantial short-term increases in HIV and HCV acquisition risk among PWID and could be a significant driver of HCV and HIV transmission among PWID. These findings support the need for developing novel interventions to minimise the risk of HCV and HIV acquisition, including addressing structural risks associated with drug laws and excessive incarceration of PWID. Funding: Engineering and Physical Sciences Research Council, National Institute for Health Research, National Institutes of Health.