Partial melting in the Earth's mantle plays an important part in generating the geochemical and isotopic diversity observed in volcanic rocks at the surface. Identifying the composition of these primary melts in the mantle is crucial for establishing links between mantle geochemical 'reservoirs' and fundamental geodynamic processes. Mineral inclusions in natural diamonds have provided a unique window into such deep mantle processes. Here we provide experimental and geochemical evidence that silicate mineral inclusions in diamonds from Juina, Brazil, crystallized from primary and evolved carbonatite melts in the mantle transition zone and deep upper mantle. The incompatible trace element abundances calculated for a melt coexisting with a calcium-titanium-silicate perovskite inclusion indicate deep melting of carbonated oceanic crust, probably at transition-zone depths. Further to perovskite, calcic-majorite garnet inclusions record crystallization in the deep upper mantle from an evolved melt that closely resembles estimates of primitive carbonatite on the basis of volcanic rocks. Small-degree melts of subducted crust can be viewed as agents of chemical mass-transfer in the upper mantle and transition zone, leaving a chemical imprint of ocean crust that can possibly endure for billions of years.