  The field equations in $f(R)$ gravity derived from the Palatini variational
principle and formulated in the Einstein conformal frame yield a cosmological
term which varies with time. Moreover, they break the conservation of the
energy--momentum tensor for matter, generating the interaction between matter
and dark energy. Unlike phenomenological models of interacting dark energy,
$f(R)$ gravity derives such an interaction from a covariant Lagrangian which is
a function of a relativistically invariant quantity (the curvature scalar $R$).
We derive the expressions for the quantities describing this interaction in
terms of an arbitrary function $f(R)$, and examine how the simplest
phenomenological models of a variable cosmological constant are related to
$f(R)$ gravity. Particularly, we show that $\Lambda c^2=H^2(1-2q)$ for a flat,
homogeneous and isotropic, pressureless universe. For the Lagrangian of form
$R-1/R$, which is the simplest way of introducing current cosmic acceleration
in $f(R)$ gravity, the predicted matter--dark energy interaction rate changes
significantly in time, and its current value is relatively weak (on the order
of 1% of $H_0$), in agreement with astronomical observations.
