  In this paper we prove a higher dimensional analogue of Carleson's
$\varepsilon^2$ conjecture. Given two arbitrary disjoint open sets
$\Omega^+,\Omega^-\subset \mathbb{R}^{n+1}$, and $x\in\mathbb{R}^{n+1}$, $r>0$,
we denote $$\varepsilon_n(x,r) := \frac{1}{r^n}\, \inf_{H^+} \mathcal{H}^n
\left( ((\partial B(x,r)\cap H^+) \setminus \Omega^+) \cup ((\partial
B(x,r)\cap H^-) \setminus \Omega^-)\right),$$ where the infimum is taken over
all open affine half-spaces $H^+$ such that $x \in \partial H^+$ and we define
$H^-= \mathbb{R}^{n+1} \setminus \overline {H^{+}}$. Our first main result
asserts that any Borel subset of $$\left\{x\in\mathbb{R}^{n+1}\, :\, \int_0^1
\varepsilon_n(x,r)^2 \, \frac{dr}{r}<\infty\right\}$$ is $n$-rectifiable. For
our second main result we assume that $\Omega^+, \Omega^-$ are open and that
$\Omega^+\cup\Omega^-$ satisfies the capacity density condition. For each $x
\in \partial \Omega^+ \cup \partial \Omega^-$ and $r>0$, we denote by
$\alpha^\pm(x,r)$ the characteristic constant of the (spherical) open sets
$\Omega^\pm \cap \partial B(x,r)$. We show that, up to a set of $\mathcal{H}^n$
measure zero, $x$ is a tangent point for both $\partial \Omega^+$ and $
\partial \Omega^-$ if and only if\begin{equation*}
  \int_0^{1} \min(1,\alpha^+(x,r) + \alpha^-(x,r) -2) \frac{dr}{r} < \infty.
  \end{equation*} The first result is new even in the plane and the second one
improves and extends to higher dimensions the $\varepsilon^2$ conjecture of
Carleson.
