Nearly 30% of individuals with gestational diabetes (GDM) do not achieve glycemic control with lifestyle modification alone and require medication treatment. Oral agents, such as glyburide, have several advantages over insulin for the treatment of GDM, including greater patient acceptance; however, the effectiveness of glyburide for the treatment of GDM remains controversial. To compare the perinatal and neonatal outcomes associated with glyburide vs insulin using causal inference methods in a clinical setting with information on glycemic control. The population-based cohort study included patients with GDM who required medication treatment from 2007 to 2017 in Kaiser Permanente Northern California. Machine learning and rigorous casual inference methods with time-varying exposures were used to evaluate associations of exposure to glyburide vs insulin with perinatal outcomes. Data analysis was conducted from March 2018 to July 2017. Time-varying exposure to glyburide vs insulin during pregnancy. Outcomes evaluated separately included neonatal hypoglycemia, jaundice, shoulder dystocia, respiratory distress syndrome (RDS), neonatal intensive care unit (NICU) admission, size-for-gestational age, and cesarean delivery. Inverse probability weighting (IPW) estimation was used to separately compare perinatal outcomes between those initiating glyburide and insulin. This approach was combined with Super Learning for propensity score estimation to account for both baseline and time-dependent confounding in both per-protocol (primary) and intention-to-treat (secondary) analyses to evaluate sustained exposure to the same therapy. From 2007 to 2017, 11 321 patients with GDM (mean [SD] age, 32.9 [4.9] years) initiated glyburide or insulin during pregnancy. In multivariate models, the risk of neonatal respiratory distress was 2.03 (95% CI, 0.13-3.92) per 100 births lower and the risk of NICU admission was 3.32 (95% CI, 0.20-6.45) per 100 births lower after continuous exposure to glyburide compared with insulin. There were no statistically significant differences in glyburide vs insulin initiation in risk for neonatal hypoglycemia (0.85 [95% CI, -1.17 to 2.86] per 100 births), jaundice (0.02 [95% CI, -1.46 to 1.51] per 100 births), shoulder dystocia (-1.05 [95% CI, -2.71 to 0.62] per 100 births), or large-for-gestational age categories (-2.75 [95% CI, -6.31 to 0.80] per 100 births). Using data from a clinical setting and contemporary causal inference methods, our findings do not provide evidence of a difference in the outcomes examined between patients with GDM initiating glyburide compared with those initiating insulin.