Kontsevich's formality theorem states that there exists an L-infinity quasi-isomorphism from the dgla T-poly(.)(M) of polyvector fields on a smooth manifold M to the dgla D-poly(. )(M) of polydifferential operators on M, which extends the classical Hochschild-Kostant-Rosenberg map. In this paper, we extend Kontsevich's formality theorem to Lie pairs, a framework which includes a range of diverse geometric contexts such as complex manifolds, foliations, and g-manifolds (that is, manifolds endowed with an action of a Lie algebra g). The spaces tot (Gamma(Lambda(.)A(boolean OR))circle times(R) T-poly(.)) and tot (Gamma(Lambda(.)A(boolean OR))circle times(R) D-poly(.)) associated with a Lie pair (L, A) each carry an L-infinity algebra structure canonical up to L-infinity isomorphism. These two spaces serve as replacements for the spaces of polyvector fields and polydifferential operators, respectively. Their corresponding cohomology groups H-CE(.)(A, T-poly(.)) and H-CE(.)(A, D-poly(.)) admit canonical Gerstenhaber algebra structures. We establish the following formality theorem for Lie pairs: there exists an L-infinity quasi-isomorphism from tot (Gamma(Lambda(.)A(boolean OR))circle times(R) T-poly(.)) to tot Gamma(Lambda(.)A(boolean OR))circle times(R) D-poly(.)) whose first Taylor coefficient is equal to hkr o(td(L/A)(del))(1/2). Here the cocycle (td(L/A)boolean OR)(1/2) acts on tot (Gamma(Lambda(.)A(boolean OR))circle times(R) T-poly(.)) by contraction. Furthermore, we prove a Kontsevich-Duflo type theorem for Lie pairs: the Hochschild-Kostant-Rosenberg map twisted by the square root of the Todd class of the Lie pair (L, A) is an isomorphism of Gerstenhaber algebras from H-CE(.)(A, T-poly(.)) to H-CE(.)(A, D-poly(.)). As applications, we establish formality and Kontsevich-Duflo type theorems for complex manifolds, foliations, and g-manifolds. In the case of complex manifolds, We recover the Kontsevich-Duflo theorem of complex geometry. (C) 2019 Elsevier Inc. All rights reserved.