We study the maximum number $ex(n,e,H)$ of copies of a graph $H$ in graphs with given number of vertices and edges. We show that for any fixed graph $H$, $ex(n,e,H)$ is asymptotically realized by the quasi-clique provided that the edge density is sufficiently large. We also investigate a variant of this problem, when the host graph is bipartite.