Among the myriad discoveries presented in the second data release of the Gaia mission, there was an enigmatic color-magnitude diagram (CMD) of Milky Way halo stars, showing a striking double (blue/red) sequence. The blue sequence was linked to a major merger that our Galaxy experienced early in its history (Gaia-Enceladus). The origin of the red sequence was unclear, and it was generally associated, because of its chemical composition, with the Milky Way thick disk. However, the lack of accurate ages precluded a clear understanding of its nature. We compared this double-sequenced observed CMD with synthetic CMDs coming directly from stellar evolution theory. This technique has been successfully used to study the star formation history of Local Group dwarf galaxies. Thanks to the accurate distances provided by Gaia for millions of stars beyond the immediate solar neighborhood, we could apply this technique to characterize their stellar age and metallicity distributions. In this way, we discovered that the stars in both halo sequences were formed more than 10 billion years ago, and shared a basically identical age distribution. They were older on average than the Milky Way's thick disk, which contained stars as old as those in the halo, but also younger stars. The different location in the CMD of the two sequences was due to their different chemical enrichment histories, the blue stars having lower metallicity than the stars in the red sequence. To put these findings within a cosmological context, we used predictions from state-of-the-art cosmological simulations. This allowed us to delineate a clear picture of the formation of our Galaxy: a primitive Milky Way had been forming stars during some 3 Gyr when a smaller galaxy, which had been forming stars on a similar timescale but was less chemically enriched owing to its lower mass, was accreted into it. This merger heated some of the existing stars in the main progenitor into a stellar halo-like configuration (the red sequence). A ready supply of infalling gas during the merger ensured the maintenance of a disk-like configuration, with the thick disk continuing to form stars at a substantial rate. Subsequently, around 8–6 Gyr ago, the gas settled into a thin disk that has continued to form stars until the present day.