Background: Mechanical ventilation is a potentially painful and discomforting intervention that is widely used in neonatal intensive care. Newborn infants demonstrate increased sensitivity to pain, which may affect clinical and neurodevelopmental outcomes. The use of drugs that reduce pain might be important in improving survival and neurodevelopmental outcomes. Objectives: To determine the benefits and harms of opioid analgesics for neonates (term or preterm) receiving mechanical ventilation compared to placebo or no drug, other opioids, or other analgesics or sedatives. Search methods: We used the standard search strategy of Cochrane Neonatal to search the Cochrane Central Register of Controlled Trials (CENTRAL; 2020, Issue 9), in the Cochrane Library; MEDLINE via PubMed (1966 to 29 September 2020); Embase (1980 to 29 September 2020); and the Cumulative Index to Nursing and Allied Health Literature (CINAHL) (1982 to 29 September 2020). We searched clinical trials databases, conference proceedings, and the reference lists of retrieved articles for randomised controlled trials and quasi-randomised trials. Selection criteria: We included randomised and quasi-randomised controlled trials comparing opioids to placebo or no drug, to other opioids, or to other analgesics or sedatives in newborn infants on mechanical ventilation. We excluded cross-over trials. We included term (≥ 37 weeks' gestational age) and preterm (< 37 weeks' gestational age) newborn infants on mechanical ventilation. We included any duration of drug treatment and any dosage given continuously or as bolus; we excluded studies that gave opioids to ventilated infants for procedures. Data collection and analysis: For each of the included trials, we independently extracted data (e.g. number of participants, birth weight, gestational age, types of opioids) using Cochrane Effective Practice and Organisation of Care Group (EPOC) criteria and assessed the risk of bias (e.g. adequacy of randomisation, blinding, completeness of follow-up). We evaluated treatment effects using a fixed-effect model with risk ratio (RR) for categorical data and mean difference (MD) for continuous data. We used the GRADE approach to assess the certainty of evidence. Main results: We included 23 studies (enrolling 2023 infants) published between 1992 and 2019. Fifteen studies (1632 infants) compared the use of morphine or fentanyl versus placebo or no intervention. Four studies included both term and preterm infants, and one study only term infants; all other studies included only preterm infants, with five studies including only very preterm infants. We are uncertain whether opioids have an effect on the Premature Infant Pain Profile (PIPP) Scale in the first 12 hours after infusion (MD -5.74, 95% confidence interval (CI) -6.88 to -4.59; 50 participants, 2 studies) and between 12 and 48 hours after infusion (MD -0.98, 95% CI -1.35 to -0.61; 963 participants, 3 studies) because of limitations in study design, high heterogeneity (inconsistency), and imprecision of estimates (very low-certainty evidence - GRADE). The use of morphine or fentanyl probably has little or no effect in reducing duration of mechanical ventilation (MD 0.23 days, 95% CI -0.38 to 0.83; 1259 participants, 7 studies; moderate-certainty evidence because of unclear risk of bias in most studies) and neonatal mortality (RR 1.12, 95% CI 0.80 to 1.55; 1189 participants, 5 studies; moderate-certainty evidence because of imprecision of estimates). We are uncertain whether opioids have an effect on neurodevelopmental outcomes at 18 to 24 months (RR 2.00, 95% CI 0.39 to 10.29; 78 participants, 1 study; very low-certainty evidence because of serious imprecision of the estimates and indirectness). Limited data were available for the other comparisons (i.e. two studies (54 infants) on morphine versus midazolam, three (222 infants) on morphine versus fentanyl, and one each on morphine versus diamorphine (88 infants), morphine versus remifentanil (20 infants), fentanyl versus sufentanil (20 infants), and fentanyl versus remifentanil (24 infants)). For these comparisons, no meta-analysis was conducted because outcomes were reported by one study. Authors' conclusions: We are uncertain whether opioids have an effect on pain and neurodevelopmental outcomes at 18 to 24 months; the use of morphine or fentanyl probably has little or no effect in reducing the duration of mechanical ventilation and neonatal mortality. Data on the other comparisons planned in this review (opioids versus analgesics; opioids versus other opioids) are extremely limited and do not allow any conclusions. In the absence of firm evidence to support a routine policy, opioids should be used selectively - based on clinical judgement and evaluation of pain indicators - although pain measurement in newborns has limitations.