Abstract. We establish the convexity of Mabuchi's 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äh-ler 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 homogenuous Monge-Ampère equation on a product domain, whose proof uses plurisubharmonic variation of Bergman kernels.