We formulate the in-medium similarity renormalization group (IM-SRG) for open-shell nuclei using a multireference formalism based on a generalized Wick theorem introduced in quantum chemistry. The resulting multireference IM-SRG (MR-IM-SRG) is used to perform the first ab initio study of all even oxygen isotopes with chiral nucleon-nucleon and three-nucleon interactions, from the proton to the neutron drip lines. We obtain an excellent reproduction of experimental ground-state energies with quantified uncertainties, which is validated by results from the importance-truncated no-core shell model and the coupled cluster method. The agreement between conceptually different many-body approaches and experiment highlights the predictive power of current chiral two- and three-nucleon interactions, and establishes the MR-IM-SRG as a promising new tool for ab initio calculations of medium-mass nuclei far from shell closures.