We propose a definition of the Dirichlet energy (which is roughly speaking the integral of the square of the gradient) for mappings µ : Ω Ñ pPpDq, W2q defined over a subset Ω of R p and valued in the space PpDq of probability measures on a compact convex subset D of R q endowed with the quadratic Wasserstein distance. Our definition relies on a straightforward generalization of the Benamou-Brenier formula (already introduced by Brenier) but is also equivalent to the definition of Korevaar, Schoen and Jost as limit of approximate Dirichlet energies, and to the definition of Reshetnyak of Sobolev spaces valued in metric spaces.We study harmonic mappings, i.e. minimizers of the Dirichlet energy provided that the values on the boundary BΩ are fixed. The notion of constant-speed geodesics in the Wasserstein space is recovered by taking for Ω a segment of R. As the Wasserstein space pPpDq, W2q is positively curved in the sense of Alexandrov we cannot apply the theory of Korevaar, Schoen and Jost and we use instead arguments based on optimal transport. We manage to get existence of harmonic mappings provided that the boundary values are Lipschitz on BΩ, uniqueness is an open question.If Ω is a segment of R, it is known that a curve valued in the Wasserstein space PpDq can be seen as a superposition of curves valued in D. We show that it is no longer the case in higher dimensions: a generic mapping Ω Ñ PpDq cannot be represented as the superposition of mappings Ω Ñ D.We are able to show the validity of a maximum principle: the composition F˝µ of a function F : PpDq Ñ R convex along generalized geodesics and a harmonic mapping µ : Ω Ñ PpDq is a subharmonic real-valued function.We also study the special case where we restrict ourselves to a given family of elliptically contoured distributions (a finite-dimensional and geodesically convex submanifold of pPpDq, W2q which generalizes the case of Gaussian measures) and show that it boils down to harmonic mappings valued in the Riemannian manifold of symmetric matrices endowed with the distance coming from optimal transport. 14 3. The Dirichlet energy and the space H 1 pΩ, PpDqq 15 3.1. A Benamou-Brenier type definition 17 3.2. The smooth case 20