Measures of exoplanet bulk densities indicate that small exoplanets with radius less than 3 Earth radii ($R_oplus$) range from low-density sub-Neptunes containing volatile elements to higher density rocky planets with Earth-like or iron-rich (Mercury-like) compositions. Such astonishing diversity in observed small exoplanet compositions may be the product of different initial conditions of the planet-formation process and/or different evolutionary paths that altered the planetary properties after formation. Planet evolution may be especially affected by either photoevaporative mass loss induced by high stellar X-ray and extreme ultraviolet (XUV) flux or giant impacts. Although there is some evidence for the former, there are no unambiguous findings so far about the occurrence of giant impacts in an exoplanet system. Here, we characterize the two innermost planets of the compact and near-resonant system Kepler-107. We show that they have nearly identical radii (about $1.5-1.6~R_oplus$), but the outer planet Kepler-107c is more than twice as dense (about $12.6~rm g,cm^{-3}$) as the innermost Kepler-107b (about $5.3~rm g,cm^{-3}$). In consequence, Kepler-107c must have a larger iron core fraction than Kepler-107b. This imbalance cannot be explained by the stellar XUV irradiation, which would conversely make the more-irradiated and less-massive planet Kepler-107b denser than Kepler-107c. Instead, the dissimilar densities are consistent with a giant impact event on Kepler-107c that would have stripped off part of its silicate mantle. This hypothesis is supported by theoretical predictions from collisional mantle stripping, which match the mass and radius of Kepler-107c.