Let G be a topological group such that its homology H(G) with coefficients in a principal ideal domain R is an exterior algebra, generated in odd degrees. We show that the singular cochain functor carries the duality between G-spaces and spaces over BG to the Koszul duality between modules up to homotopy over H(G) and H^*(BG). This gives in particular a Cartan-type model for the equivariant cohomology of a G-space. As another corollary, we obtain a multiplicative quasi-isomorphism C^*(BG) -> H^*(BG). A key step in the proof is to show that a differential Hopf algebra is formal in the category of A-infinity algebras provided that it is free over R and its homology an exterior algebra.