  Kim and Vu made the following conjecture (\textit{Advances in Mathematics},
2004): if $d\gg \log n$, then the random $d$-regular graph $\mathcal G(n,d)$
can asymptotically almost surely be "sandwiched" between $\mathcal G(n,p_1)$
and $\mathcal G(n,p_2)$ where $p_1$ and $p_2$ are both $(1+o(1))d/n$. They
proved this conjecture for $\log n\ll d\le n^{1/3-o(1)}$, with a defect in the
sandwiching: $\mathcal G(n,d)$ contains $\mathcal G(n,p_1)$ perfectly, but is
not completely contained in $\mathcal G(n,p_2)$. Recently, the embedding
$\mathcal G(n,p_1) \subseteq \mathcal G(n,d)$ was improved by Dudek, Frieze,
Ruci\'nski and \v{S}ileikis to $d=o(n)$. In this paper, we prove Kim--Vu's
sandwich conjecture, with perfect containment on both sides, for all $d\gg
n/\sqrt{\log n}$. For $d=O(n/\sqrt{\log n})$, we prove a weaker version of the
sandwich conjecture with $p_2$ approximately equal to $(d/n)\log n$, without
any defect. In addition to sandwiching regular graphs, our results cover graphs
whose degrees are asymptotically equal. The proofs rely on estimates for the
probability that a random factor of a pseudorandom graph contains a given edge,
which is of independent interest.
  As applications, we obtain new results on the properties of random graphs
with given near-regular degree sequences, including Hamiltonicity and
universality in subgraph containment. We also determine several graph
parameters in these random graphs, such as the chromatic number, small subgraph
counts, the diameter, and the independence number. We are also able to
characterise many phase transitions in edge percolation on these random graphs,
such as the threshold for the appearance of a giant component.
