We establish the convexity of Mabuchi’s
K
K
-energy functional along weak geodesics in the space of Kähler potentials on a compact Kähler manifold, thus confirming a conjecture of Chen, and give some applications in Kähler geometry, including a proof of the uniqueness of constant scalar curvature metrics (or more generally extremal metrics) modulo automorphisms. The key ingredient is a new local positivity property of weak solutions to the homogeneous Monge-Ampère equation on a product domain, whose proof uses plurisubharmonic variation of Bergman kernels.