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\ensuremath{\approx}0.15$ 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{\mathrm{MS}}$-renormalized masses are ${m}_{u}(2\text{ }\text{ }\mathrm{GeV})=\phantom{\rule{0ex}{0ex}}2.130(41)\text{ }\text{ }\mathrm{MeV}$, ${m}_{d}(2\text{ }\text{ }\mathrm{GeV})=4.675(56)\text{ }\text{ }\mathrm{MeV}$, ${m}_{s}(2\text{ }\text{ }\mathrm{GeV})=92.47(69)\text{ }\text{ }\mathrm{MeV}$, ${m}_{c}(3\text{ }\text{ }\mathrm{GeV})=\phantom{\rule{0ex}{0ex}}983.7(5.6)\text{ }\text{ }\mathrm{MeV}$, and ${m}_{c}({m}_{c})=1273(10)\text{ }\text{ }\mathrm{MeV}$, with four active flavors; and ${m}_{b}({m}_{b})=4195(14)\text{ }\text{ }\mathrm{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 ${\ensuremath{\alpha}}_{s}^{4}$. As byproducts of our method, we obtain the matrix elements of HQET operators with dimension 4 and 5: ${\overline{\mathrm{\ensuremath{\Lambda}}}}_{\mathrm{MRS}}=555(31)\text{ }\text{ }\mathrm{MeV}$ in the minimal renormalon-subtracted (MRS) scheme, ${\ensuremath{\mu}}_{\ensuremath{\pi}}^{2}=0.05(22)\text{ }\text{ }{\mathrm{GeV}}^{2}$, and ${\ensuremath{\mu}}_{G}^{2}({m}_{b})=0.38(2)\text{ }\text{ }{\mathrm{GeV}}^{2}$. The MRS scheme [Phys. Rev. D 97, 034503 (2018)] is the key new aspect of our method.