We present a new approach to the amenability of groupoids (both in the measure theoretical and the topological setups) based on using Markov operators. We introduce the notion of an invariant Markov operator on a groupoid and show that the Liouville property (absence of non-trivial bounded harmonic functions) for such an operator implies amenability of the groupoid. Moreover, the groupoid action on the Poisson boundary of any invariant operator is always amenable. This approach subsumes as particular cases numerous earlier results on amenability for groups, actions, equivalence relations and foliations. For instance, we establish in a unified way topological amenability of the boundary action for isometry groups of Gromov hyperbolic spaces, Riemannian symmetric spaces and affine buildings.