We introduce a gauge and diffeomorphism invariant theory on the Yang-Mills phase space. The theory is well defined for an arbitrary gauge group with an invariant bilinear form, it contains only first class constraints, and the spacetime metric has a simple form in terms of the phase space variables. With gauge group SO (3, C), the theory equals the Ashtekar formulation of gravity with a cosmological constant. For Lorentzian signature, the theory is complex, and we have not found any good reality conditions. In the Euclidean signature case, everything is real. In a weak field expansion around de Sitter spacetime, the theory is shown to give the conventional Yang-Mills theory to the lowest order in the fields. We show that the coupling to a Higgs scalar is straightforward, while the naive spinor coupling does not work. We have not found any way of including spinors that gives a closed constraint algebra. For gauge group U(2), we find a static and spherically symmetric solution.