The goal of the paper is to give an optimal transport formulation of the full Einstein equations of general relativity, linking the (Ricci) curvature of a space-time with the cosmological constant and the energy-momentum tensor. Such an optimal transport formulation is in terms of convexity/concavity properties of the Boltzmann–Shannon entropy along curves of probability measures extremizing suitable optimal transport costs. The result gives a new connection between general relativity and optimal transport; moreover, it gives a mathematical reinforcement of the strong link between general relativity and thermodynamics/information theory that emerged in the physics literature of the last years.