Comparisons of gene trees and species trees are key to understanding major processes of genome evolution such as gene duplication and loss. Because current methods to reconstruct phylogenies fail to model the two-way dependency between gene trees and the species tree, they often misrepresent gene and species histories. We present a new probabilistic model to jointly infer rooted species and gene trees for dozens of genomes and thousands of gene families. We use simulations to show that this method accurately infers the species tree and gene trees, is robust to misspecification of the models of sequence and gene family evolution, and provides a precise historic record of gene duplications and losses throughout genome evolution. We simultaneously reconstruct the history of mammalian species and their genes based on 36 completely sequenced genomes, and use the reconstructed gene trees to infer the gene content and organization of ancestral mammalian genomes. We show that our method yields a more accurate picture of ancestral genomes than the trees available in the authoritative database Ensembl.[Supplemental material is available for this article.]The reconstruction of gene phylogenies based on sequences alone is difficult. First, homologous sequences are often hard to align unambiguously (Wong et al. 2008), which leads to incorrect gene trees and erroneous predictions of events of duplications and losses. Second, sequence alignments generally contain insufficient information to accurately model gene evolution and thus understand their history, as suggested by the positive correlation found between sequence length and congruence to the species tree (Galtier 2007). However, knowing the relationships among the species in which these sequences have evolved can improve gene tree inference. Several methods have successfully implemented this idea by combining sequence evolution models with a model of gene evolution that accounts for duplication and loss (DL) (Vilella et al. 2008;Akerborg et al. 2009;Flicek et al. 2010; Kellis 2010, 2012). Provided the species tree is known, these methods yield significantly better gene trees than other molecular phylogenetic methods. However, because reference species trees themselves generally rely on molecular data, they can be also affected by phylogenetic reconstruction uncertainties and unidentified events of gene duplication and loss. This reveals a circular problem: the reconstruction of a species tree requires identifying events of gene family evolution such as DLs, and both the reconstruction of gene trees and the identification of duplications and losses requires a known species tree. The solution to the conundrum is to explicitly consider this two-way dependence and jointly reconstruct the species phylogeny and the histories of all gene families present in their genomes.The coestimation of gene and species trees requires that several gene families be analyzed simultaneously. This represents a significant departure from existing methods (Vilella et al. 2008;Akerborg et al. 200...