Valid causal inference from observational studies requires controlling for confounders. When time-dependent confounders are present that serve as mediators of treatment effects and affect future treatment assignment, standard regression methods for controlling for confounders fail. Similar issues also arise in trials with sequential randomization, when randomization at later time points is based on intermediate outcomes from earlier randomized assignments. We propose a robust multiple imputation-based approach to causal inference in this setting called penalized spline of propensity methods for treatment comparison (PENCOMP), which builds on the penalized spline of propensity prediction method for missing data problems. PENCOMP estimates causal effects by imputing missing potential outcomes with flexible spline models and draws inference based on imputed and observed outcomes. Under the SUTVA, positivity, and ignorability assumptions, PENCOMP has a double robustness property for causal effects. Simulations suggest that it tends to outperform doubly robust marginal structural modeling when the weights are variable. We apply our method to the multicenter AIDS cohort study to estimate the effect of antiretroviral treatment on CD4 counts in HIV-infected patients. Supplementary materials for this article are available online. Code submitted with this article was checked by an Associate Editor for Reproducibility and is available as an online supplement.