Ammonia-oxidizing archaea (AOA) of the phylum Thaumarchaeota are widespread in marine and terrestrial habitats, playing a major role in the global nitrogen cycle. However, their evolutionary history remains unexplored, which limits our understanding of their adaptation mechanisms. Here, our comprehensive phylogenomic tree of Thaumarchaeota supports three sequential events: origin of AOA from terrestrial non-AOA ancestors, colonization of the shallow ocean, and expansion to the deep ocean. Careful molecular dating suggests that these events coincided with the Great Oxygenation Event around 2300 million years ago (Mya), and oxygenation of the shallow and deep ocean around 800 and 635-560 Mya, respectively. The first transition was likely enabled by the gain of an aerobic pathway for energy production by ammonia oxidation and biosynthetic pathways for cobalamin and biotin that act as cofactors in aerobic metabolism. The first transition was also accompanied by the loss of dissimilatory nitrate and sulfate reduction, loss of oxygen-sensitive pyruvate oxidoreductase, which reduces pyruvate to acetyl-CoA, and loss of the Wood-Ljungdahl pathway for anaerobic carbon fixation. The second transition involved gain of a K(+) transporter and of the biosynthetic pathway for ectoine, which may function as an osmoprotectant. The third transition was accompanied by the loss of the uvr system for repairing ultraviolet light-induced DNA lesions. We conclude that oxygen availability drove the terrestrial origin of AOA and their expansion to the photic and dark oceans, and that the stressors encountered during these events were partially overcome by gene acquisitions from Euryarchaeota and Bacteria, among other sources.