Using the $L^2$ norm of the Higgs field as a Morse function, we study the moduli spaces of $U(p,q)$-Higgs bundles over a Riemann surface. We require that the genus of the surface be at least two, but place no constraints on $(p,q)$. A key step is the identification of the function's local minima as moduli spaces of holomorphic triples. We prove that these moduli spaces of triples are irreducible and non-empty. Because of the relation between flat bundles and fundamental group representations, we can interpret our conclusions as results about the number of connected components in the moduli space of semisimple $PU(p,q)$-representations. The topological invariants of the flat bundles bundle are used to label components. These invariants are bounded by a Milnor-Wood type inequality. For each allowed value of the invariants satisfying a certain coprimality condition, we prove that the corresponding component is non-empty and connected. If the coprimality condition does not hold, our results apply to the irreducible representations.