  We consider an algebraic variety and its foliation, both defined over a
number field. We prove upper bounds for the geometric complexity of the
intersection between a leaf of the foliation and a subvariety of complementary
dimension (also defined over a number field). Our bounds depend polynomially on
the degrees, logarithmic heights, and the logarithmic distance to a certain
\emph{locus of unlikely intersections}. Under suitable conditions on the
foliation, we show that this implies a bound, polynomial in the degree and
height, for the number of algebraic points on transcendental sets defined using
such foliations.
  We deduce several results in Diophantine geometry. i) Following
Masser-Zannier, we prove that given a pair of sections $P,Q$ of a
non-isotrivial family of squares of elliptic curves that do not satisfy a
constant relation, whenever $P,Q$ are simultaneously torsion their order of
torsion is bounded effectively by a polynomial in the degrees and log-heights
of the sections $P,Q$. In particular the set of such simultaneous torsion
points is effectively computable in polynomial time. ii) Following Pila, we
prove that given $V\subset\mathbb{C}^n$ there is an (ineffective) upper bound,
polynomial in the degree and log-height of V, for the degrees and discriminants
of maximal special subvarieties. In particular it follows that Andr\'e-Oort for
powers of the modular curve is decidable in polynomial time (by an algorithm
depending on a universal, ineffective Siegel constant). iii) Following Schmidt,
we show that our counting result implies a Galois-orbit lower bound for torsion
points on elliptic curves of the type previously obtained using transcendence
methods by David.
