In 785 mother-child (50% male) pairs from a longitudinal epidemiological birth cohort, we investigated associations between inflammation-related epigenetic polygenic risk scores (i-ePGS), environmental exposures, cognitive function, and child and adolescent internalizing and externalizing problems. We examined prenatal and postnatal effects. For externalizing problems, one prenatal effect was found: i-ePGS at birth associated with higher externalizing problems (ages 7-15) indirectly through lower cognitive function (age 7). For internalizing problems, we identified two effects. For a prenatal effect, i-ePGS at birth associated with higher internalizing symptoms via continuity in i-ePGS at age 7. For a postnatal effect, higher postnatal adversity exposure (birth through age 7) associated with higher internalizing problems (ages 7-15) via higher i-ePGS (age 7). Hence, externalizing problems were related mainly to prenatal effects involving lower cognitive function, whereas internalizing problems appeared related to both prenatal and postnatal effects. The present study supports a link between i-ePGS and child and adolescent mental health.