We prove a general theorem about the maximum spectral radius of connected graphs with n vertices and e edges and use it to determine the graphs with maximum spectral radius when $e\leq n+5$ and $n$ is sufficiently large.