  Let $\mathbf{k} := (k_1,\dots,k_s)$ be a sequence of natural numbers. For a
graph $G$, let $F(G;\mathbf{k})$ denote the number of colourings of the edges
of $G$ with colours $1,\dots,s$ such that, for every $c \in \{1,\dots,s\}$, the
edges of colour $c$ contain no clique of order $k_c$. Write $F(n;\mathbf{k})$
to denote the maximum of $F(G;\mathbf{k})$ over all graphs $G$ on $n$ vertices.
This problem was first considered by Erd\H{o}s and Rothschild in 1974, but it
has been solved only for a very small number of non-trivial cases.
  We prove that, for every $\mathbf{k}$ and $n$, there is a complete
multipartite graph $G$ on $n$ vertices with $F(G;\mathbf{k}) =
F(n;\mathbf{k})$. Also, for every $\mathbf{k}$ we construct a finite
optimisation problem whose maximum is equal to the limit of $\log_2
F(n;\mathbf{k})/{n\choose 2}$ as $n$ tends to infinity. Our final result is a
stability theorem for complete multipartite graphs $G$, describing the
asymptotic structure of such $G$ with $F(G;\mathbf{k}) = F(n;\mathbf{k}) \cdot
2^{o(n^2)}$ in terms of solutions to the optimisation problem.
