We develop the theory of maximal representations of the fundamental group π1(Σ) of a compact connected oriented surface Σ (possibly with boundary) into Lie groups G of Hermitian type. For any homomorphism ρ:π1(Σ)→G, we define the Toledo invariant T(Σ,ρ), a numerical invariant which has both topological and analytical interpretations. We establish important properties of T(Σ,ρ), among which continuity, uniform boundedness on the representation variety, additivity under connected sum of surfaces and congruence relations mod ℤ. We thus obtain information about the representation variety as well as striking geometric properties of maximal representations, that is representations whose Toledo invariant achieves the maximum value.
Moreover we establish properties of boundary maps associated to maximal representations which generalize naturally monotonicity properties of semiconjugations of the circle.
We define a rotation number function for general locally compact groups and study it in detail for groups of Hermitian type. Properties of the rotation number, together with the existence of boundary maps, lead to additional invariants for maximal representations and show that the subset of maximal representations is always real semialgebraic.