  Szemer\'edi's regularity lemma is a fundamental tool in extremal
combinatorics. However, the original version is only helpful in studying dense
graphs. In the 1990s, Kohayakawa and R\"odl proved an analogue of Szemer\'edi's
regularity lemma for sparse graphs as part of a general program toward
extending extremal results to sparse graphs. Many of the key applications of
Szemer\'edi's regularity lemma use an associated counting lemma. In order to
prove extensions of these results which also apply to sparse graphs, it
remained a well-known open problem to prove a counting lemma in sparse graphs.
  The main advance of this paper lies in a new counting lemma, proved following
the functional approach of Gowers, which complements the sparse regularity
lemma of Kohayakawa and R\"odl, allowing us to count small graphs in regular
subgraphs of a sufficiently pseudorandom graph. We use this to prove sparse
extensions of several well-known combinatorial theorems, including the removal
lemmas for graphs and groups, the Erd\H{o}s-Stone-Simonovits theorem and
Ramsey's theorem. These results extend and improve upon a substantial body of
previous work.
