  We study the implications of Planck data for models of dark energy (DE) and
modified gravity (MG), beyond the cosmological constant scenario. We start with
cases where the DE only directly affects the background evolution, considering
Taylor expansions of the equation of state, principal component analysis and
parameterizations related to the potential of a minimally coupled DE scalar
field. When estimating the density of DE at early times, we significantly
improve present constraints. We then move to general parameterizations of the
DE or MG perturbations that encompass both effective field theories and the
phenomenology of gravitational potentials in MG models. Lastly, we test a range
of specific models, such as k-essence, f(R) theories and coupled DE. In
addition to the latest Planck data, for our main analyses we use baryonic
acoustic oscillations, type-Ia supernovae and local measurements of the Hubble
constant. We further show the impact of measurements of the cosmological
perturbations, such as redshift-space distortions and weak gravitational
lensing. These additional probes are important tools for testing MG models and
for breaking degeneracies that are still present in the combination of Planck
and background data sets. All results that include only background
parameterizations are in agreement with LCDM. When testing models that also
change perturbations (even when the background is fixed to LCDM), some tensions
appear in a few scenarios: the maximum one found is \sim 2 sigma for Planck
TT+lowP when parameterizing observables related to the gravitational potentials
with a chosen time dependence; the tension increases to at most 3 sigma when
external data sets are included. It however disappears when including CMB
lensing.
