  $\newcommand{\poly}{_{\operatorname{poly}}^{\bullet}}\newcommand{\td}{(\operatorname{td}_{L/A}^{\nabla})^{\frac{1}{2}}}\newcommand{\cx}[1]{\operatorname{tot}\big(\Gamma(\Lambda^\bullet
A^\vee)\otimes_R\mathcal{#1}\poly\big)}\newcommand{\cy}[1]{\mathbb{H}^\bullet_{\operatorname{CE}}(A,\mathcal{#1}\poly)}$Kontsevich's
formality theorem states that there exists an $L_\infty$ 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
$\mathfrak{g}$-manifolds. The spaces $\cx{T}$ and $\cx{D}$ associated with a
Lie pair $(L,A)$ each carry an $L_\infty$ algebra structure canonical up to
$L_\infty$ isomorphism. These two spaces serve as replacements for the spaces
of polyvector fields and polydifferential operators, respectively. Their
corresponding cohomology groups $\cy{T}$ and $\cy{D}$ admit canonical
Gerstenhaber algebra structures. We establish the following formality theorem
for Lie pairs: there exists an $L_\infty$ quasi isomorphism from $\cx{T}$ to
$\cx{D}$ whose first Taylor coefficient is equal to
$\operatorname{hkr}\circ\td$. Here $\td$ acts on $\cx{T}$ 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
$\cy{T}$ to $\cy{D}$. As applications, we establish formality theorems and
Kontsevich--Duflo type theorems for complex manifolds, foliations, and
$\mathfrak{g}$-manifolds. In the case of complex manifolds, we recover the
Kontsevich--Duflo theorem of complex geometry.
