One major problem in the application of TiO2 and other oxides as an electron transport layer and optical window in perovskite solar cells (PSCs) is the nonstoichiometric defects related to oxygen vacancies. We report the studies of a TiO2 compact layer annealed in ambient air and in an oxygen environment, and the consequences on planar PSC performance. Chemical analysis and optical studies indicate that oxygen vacancy density can be significantly reduced by changing annealing conditions, leading to higher optical transmission of the TiO2 layer and retarded carrier recombination in the PSC. The carrier dynamics studies found that the electron recombination lifetime was significantly increased. With an improved electron transport layer, the power conversion efficiency of PSCs with a TiO2 compact layer annealed in oxygen was increased from 13.58% to 15.85%, due to a largely enhanced current density when compared to the control PSCs with TiO2 annealed in ambient air.