We calculate---for the first time in three-flavor lattice QCD---the hadronic matrix elements of all five local operators that contribute to neutral $B^0$- and $B_s$-meson mixing in and beyond the Standard Model. We present a complete error budget for each matrix element and also provide the full set of correlations among the matrix elements. We also present the corresponding bag parameters and their correlations, as well as specific combinations of the mixing matrix elements that enter the expression for the neutral $B$-meson width difference. We obtain the most precise determination to date of the SU(3)-breaking ratio $xi = 1.206(18)(6)$, where the second error stems from the omission of charm sea quarks, while the first encompasses all other uncertainties. The threefold reduction in total uncertainty, relative to the 2013 Flavor Lattice Averaging Group results, tightens the constraint from $B$ mixing on the Cabibbo-Kobayashi-Maskawa (CKM) unitarity triangle. Our calculation employs gauge-field ensembles generated by the MILC Collaboration with four lattice spacings and pion masses close to the physical value. We use the asqtad-improved staggered action for the light valence quarks, and the Fermilab method for the bottom quark. We use heavy-light meson chiral perturbation theory modified to include lattice-spacing effects to extrapolate the five matrix elements to the physical point. We combine our results with experimental measurements of the neutral $B$-meson oscillation frequencies to determine the CKM matrix elements $|V_{td}| = 8.00(34)(8) times 10^{-3}$, $|V_{ts}| = 39.0(1.2)(0.4) times 10^{-3}$, and $|V_{td}/V_{ts}| = 0.2052(31)(10)$, which differ from CKM-unitarity expectations by about 2$sigma$. These results and others from flavor-changing-neutral currents point towards an emerging tension between weak processes that are mediated at the loop and tree levels.