Density-functional theory was used to compute energy-minimum configurations and formation energies of substitutional and interstitial oxygen (O) in wurtzite GaN. The results indicate that O substituted at a N site (O-N) acts as a single donor with the ionized state (O-N(+1)) being the most stable O state in p-type GaN. In n-type GaN, interstitial O (O-I) is predicted to be a double acceptor and O substituted at a Ga site (O-Ga) is predicted to be a triple acceptor. The formation energies of these two species are comparable to that of O-N in n-type GaN and, as such, they should form and compensate the O-N donors. The extent of compensation was estimated for both Ga-rich and N-rich conditions with a total O concentration of 10(17) cm(-3). Ga-rich conditions yielded negligible compensation and an O-N concentration in excess of 9.9x10(16) cm(-3). N-rich conditions yielded a 25% lower O-N concentration, due to the increased stability of O-I and O-Ga relative to O-N, and moderate compensation. These findings are consistent with experimental results indicating that O acts as a donor in GaN(O). Complexes of O-N with the Mg acceptor and O-I with the Si donor were examined. Binding energies for charge-conserving reactions were >= 0.5 eV, indicating that these complexes can exist in equilibrium at room temperature. Complexes of O-N with the Ga vacancy in n-type GaN were also examined and their binding energies were 1.2 and 1.4 eV, indicating that appreciable concentrations can exist in equilibrium even at elevated temperatures. (c) 2005 American Institute of Physics.