We report the electronic structures of Ta-doped anatase TiO2 thin films grown by pulsed laser deposition (PLD) with varying magnetization using a combination of first-principles calculations and near-edge x-ray absorption fine structure (NEXAFS) spectroscopy. The roles of Ta doping and Ti vacancies are clarified, and the observed room-temperature ferromagnetism is attributed to the localized magnetic moments at Ti vacancy sites ferromagnetically ordered by electron charge carriers. O K-edge spectra exhibit significant polarization dependence which is discussed and supported by first-principles calculations in relation to both the crystal symmetry and the formation of defects. In particular, anomalous spectral-weight transfer across the entire O K edge for the ferromagnetic thin film is associated exclusively with the occurrence of Ti vacancies and strong correlation effects, which result in the enhancement of the direct interaction between oxygen sites and of the anisotropy of the eg-pσ hybridizations in the out-of-plane component. Our results show that O K-edge NEXAFS spectra can provide reliable experimental probes capable of revealing cationic defects that are intimately related to the ferromagnetism in transition metal oxides. © 2013 American Physical Society.