Phase transitions and the chemical composition of minerals in Earth's interior influence geophysical interpretations of its deep structure and dynamics. A pressure-induced spin transition in olivine has been suggested to influence iron partitioning and depletion, resulting in a distinct layered structure in Earth's lower mantle. For a more realistic mantle composition (pyrolite), we observed a considerable change in the iron-magnesium partition coefficient at about 40 gigapascals that is explained by a spin transition at much lower pressures. However, only a small depletion of iron is observed in the major high-pressure phase (magnesium silicate perovskite), which may be explained by preferential retention of the iron ion Fe3+. Changes in mineral proportions or density are not associated with the change in partition coefficient. The observed density profile agrees well with seismological models, which suggests that pyrolite is a good model composition for the upper to middle parts of the lower mantle.