The assembly of our Galaxy can be reconstructed using the motions and chemistry of individual stars1,2. Chemo-dynamical studies of the stellar halo near the Sun have indicated the presence of multiple components3, such as streams4 and clumps5, as well as correlations between the stars’ chemical abundances and orbital parameters6–8. Recently, analyses of two large stellar surveys9,10 revealed the presence of a well populated elemental abundance sequence7,11, two distinct sequences in the colour–magnitude diagram12 and a prominent, slightly retrograde kinematic structure13,14 in the halo near the Sun, which may trace an important accretion event experienced by the Galaxy15. However, the link between these observations and their implications for Galactic history is not well understood. Here we report an analysis of the kinematics, chemistry, age and spatial distribution of stars that are mainly linked to two major Galactic components: the thick disk and the stellar halo. We demonstrate that the inner halo is dominated by debris from an object that at infall was slightly more massive than the Small Magellanic Cloud, and which we refer to as Gaia–Enceladus. The stars that originate in Gaia–Enceladus cover nearly the full sky, and their motions reveal the presence of streams and slightly retrograde and elongated trajectories. With an estimated mass ratio of four to one, the merger of the Milky Way with Gaia–Enceladus must have led to the dynamical heating of the precursor of the Galactic thick disk, thus contributing to the formation of this component approximately ten billion years ago. These findings are in line with the results of galaxy formation simulations, which predict that the inner stellar halo should be dominated by debris from only a few massive progenitors2,16.