Abstract. Let P → B be a principal G-bundle. For any connection θ on P , the Chern-Weil construction of characteristic classes defines an algebra homomorphism from the Weil algebra W g = Sg * ⊗ ∧g * into the algebra of differential forms A = Ω(P ). Invariant polynomials (Sg * )inv ⊂ W g map to cocycles, and the induced map in cohomology (Sg * )inv → H(A basic ) is independent of the choice of θ. The algebra Ω(P ) is an example of a commutative g-differential algebra with connection, as introduced by H. Cartan in 1950. As observed by Cartan, the Chern-Weil construction generalizes to all such algebras.In this paper, we introduce a canonical Chern-Weil map W g → A for possibly noncommutative g-differential algebras with connection. Our main observation is that the generalized Chern-Weil map is an algebra homomorphism "up to g-homotopy". Hence, the induced map (Sg * )inv → H basic (A) is an algebra homomorphism. As in the standard Chern-Weil theory, this map is independent of the choice of connection.Applications of our results include: a conceptually easy proof of the Duflo theorem for quadratic Lie algebras, a short proof of a conjecture of Vogan on Dirac cohomology, generalized Harish-Chandra projections for quadratic Lie algebras, an extension of Rouvière's theorem for symmetric pairs, and a new construction of universal characteristic forms in the Bott-Shulman complex.