We study the connectedness of the moduli space of gauge equivalence classes of flat $G$-connections on a compact orientable surface or a compact nonorientable surface for a class of compact connected Lie groups. This class includes all the compact, connected, simply connected Lie groups, and some non-semisimple classical groups.