Many women experience anxiety or sleep disorders during pregnancy and require pharmacological treatment with benzodiazepines (BZDs) or z-hypnotics. Limited information is currently available on how prenatal exposure to these medications affects behavioral problems in children over the long term. Therefore, from a public health perspective, this issue is highly important. The present study aimed to determine whether prenatal exposure to BZDs and z-hypnotics affected externalizing and internalizing behavior problems in children at age 5 years. This study was based on The Norwegian Mother and Child Cohort Study and The Medical Birth Registry of Norway. The final study population included data for 36 401 children, from questionnaires completed by the mothers throughout the 5-year follow up. Children's behaviors were measured at age 5, based on parental responses to The Child Behavior Checklist. Children T-scores of 63 or above were considered to indicate clinically relevant behavior problems. We applied inverse probability of treatment weighting (IPTW) and log-binomial regression models to estimate risk ratios (RRs) and bootstrapped 95% confidence intervals (CIs) with censoring weights to account for loss during follow-up. Several sensitivity analyses were performed to assess the robustness of the main results. The final sample included 273 (0.75%) children that were exposed to BZDs and/or z-hypnotics during pregnancy. The main, IPTW and censoring weighted analyses showed that prenatal exposure to BZD and/or z-hypnotics increased the risks of internalizing behavioral problems (RR: 1.35, 95% CI: 0.73-2.49) and externalizing behavioral problems (RR: 1.51, 95% CI: 0.86-2.64). However, based on sensitivity analyses, we concluded that the risks of displaying externalizing and internalizing problems at 5 years of age did not significantly increase after prenatal exposure to BZDs and/or z-hypnotics. Instead, the sensitivity analyses suggested that residual confounding and selection bias might explain the increased risks observed in the main analyses.