We shall give a twisted Dirac structure on the space of irreducible connections on a S U(n)-bundle over a three-manifold, and give a family of twisted Dirac structures on the space of irreducible connections on the trivial S U(n)-bundle over a four-manifold. The twist is described by the Cartan 3-form on the space of connections. It vanishes over the subspace of flat connections. So the spaces of flat connections are endowed with ( nontwisted ) Dirac structures. The Dirac structure on the space of flat connections over the three-manifold is obtained as the boundary restriction of a corresponding Dirac structure over the four-manifold. We discuss also the action of the group of gauge transformations over these Dirac structures.