Let P be a principal bundle with semisimple compact simply connected structure group G over a compact simply connected four-manifold M. In this paper we give explicit formulas for the rational homotopy groups and cohomology algebra of the gauge group and of the space of (irreducible) connections modulo gauge transformations for any such bundle.