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≈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 MS¯-renormalized masses are mu(2 GeV)=2.130(41) MeV, md(2 GeV)=4.675(56) MeV, ms(2 GeV)=92.47(69) MeV, mc(3 GeV)=983.7(5.6) MeV, and mc(mc)=1273(10) MeV, with four active flavors; and mb(mb)=4195(14) MeV with five active flavors. We also obtain ratios of quark masses mc/ms=11.783(25), mb/ms=53.94(12), and mb/mc=4.578(8). The result for mc 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 αs4. As byproducts of our method, we obtain the matrix elements of HQET operators with dimension 4 and 5: Λ¯MRS=555(31) MeV in the minimal renormalon-subtracted (MRS) scheme, μπ2=0.05(22) GeV2, and μG2(mb)=0.38(2) GeV2. The MRS scheme [Phys. Rev. D 97, 034503 (2018)PRVDAQ2470-001010.1103/PhysRevD.97.034503] is the key new aspect of our method.