  We calculate the up-, down-, strange-, charm-, and bottom-quark masses using
the MILC highly improved staggered-quark ensembles with four flavors of
dynamical quarks. We use ensembles at six lattice spacings ranging from
$a\approx0.15$~fm to $0.03$~fm and with both physical and unphysical values of
the two light and the strange sea-quark masses. We use a new method based on
heavy-quark effective theory (HQET) to extract quark masses from heavy-light
pseudoscalar meson masses. Combining our analysis with our separate
determination of ratios of light-quark masses we present masses of the up,
down, strange, charm, and bottom quarks. Our results for the
$\overline{\text{MS}}$-renormalized masses are $m_u(2~\text{GeV}) =
2.130(41)$~MeV, $m_d(2~\text{GeV}) = 4.675(56)$~MeV, $m_s(2~\text{GeV}) =
92.47(69)$~MeV, $m_c(3~\text{GeV}) = 983.7(5.6)$~MeV, and $m_c(m_c) =
1273(10)$~MeV, with four active flavors; and $m_b(m_b) = 4195(14)$~MeV with
five active flavors. We also obtain ratios of quark masses $m_c/m_s =
11.783(25)$, $m_b/m_s = 53.94(12)$, and $m_b/m_c = 4.578(8)$. The result for
$m_c$ matches the precision of the most precise calculation to date, and the
other masses and all quoted ratios are the most precise to date. Moreover,
these results are the first with a perturbative accuracy of $\alpha_s^4$. As
byproducts of our method, we obtain the matrix elements of HQET operators with
dimension 4 and 5: $\overline{\Lambda}_\text{MRS}=555(31)$~MeV in the minimal
renormalon-subtracted (MRS) scheme, $\mu_\pi^2 = 0.05(22)~\text{GeV}^2$, and
$\mu_G^2(m_b)=0.38(2)~\text{GeV}^2$. The MRS scheme [Phys. Rev. D97, 034503
(2018), arXiv:1712.04983 [hep-ph]] is the key new aspect of our method.
