  We study the focusing NLS equation in $\mathbb{R}^N$ in the
mass-supercritical and energy-subcritical (or intercritical) regime, with $H^1$
data at the mass-energy threshold $ \mathcal{ME}(u_0)=\mathcal{ME}(Q)$, where
$Q$ is the ground state. Previously, Duyckaerts-Merle studied the behavior of
threshold solutions in the $H^1$-critical case, in dimensions $N = 3, 4, 5$,
later generalized by Li-Zhang for higher dimensions. In the intercritical case,
Duyckaerts-Roudenko studied the threshold problem for the 3d cubic NLS
equation.
  In this paper, we generalize the results of Duyckaerts-Roudenko for any
dimension and any power of the nonlinearity for the entire intecritical range.
We show the existence of special solutions, $Q^\pm$, besides the standing wave
$e^{it}Q$, which exponentially approach the standing wave in the positive time
direction, but differ in its behavior for negative time. We classify all
solutions at the threshold level, showing either blow-up occurs in finite
(positive and negative) time, or scattering in both time directions, or the
solution is equal to one of the three special solutions above, up to
symmetries. Our proof extends to the $H^1$-critical case, thus, giving a
different and more unified approach than the Li-Zhang result.
  These results are obtained by studying the linearized equation around the
standing wave and some tailored approximate solutions to the NLS equation. We
establish important decay properties of functions associated to the spectrum of
the linearized Schr\"odinger operator, which, in combination with modulational
stability and coercivity for the linearized operator on special subspaces,
allows us to use a fixed-point argument to show the existence of special
solutions. Finally, we prove the uniqueness by studying exponentially decaying
solutions to a sequence of linearized equations.

Analysis of PDEs