  A measurement of the time-dependent ratio of the $D^0\rightarrow K^+\pi^-$ to
$\overline{D}^0\rightarrow K^+\pi^-$ decay rates is reported. The analysis uses
a sample of proton-proton collisions corresponding to an integrated luminosity
of 6 fb$^-1$ recorded by the LHCb experiment from 2015 through 2018 at a
center-of-mass energy of 13 TeV. The $D^0$ meson is required to originate from
a $D^{*+}\rightarrow D^0\pi^+$ decay, such that its flavor at production is
inferred from the charge of the accompanying pion. The measurement is performed
simultaneously for the $K^+\pi^-$ and $K^-\pi^+$ final states, allowing both
mixing and $CP$-violation parameters to be determined. The value of the ratio
of the decay rates at production is determined to be $R_{K\pi} = (343.1 \pm
2.0) \times 10^{-5}$. The mixing parameters are measured to be $c_{K\pi} =
(51.4 \pm 3.5) \times 10^{-4}$ and $c_{K\pi}^{\prime} = (13 \pm 4) \times
10^{-6}$, where $\sqrt{R_{K\pi}}c_{K\pi}$ is the linear coefficient of the
expansion of the ratio as a function of decay time in units of the $D^0$
lifetime, and $c_{K\pi}^{\prime}$ is the quadratic coefficient, both averaged
between the $K^+\pi^-$ and $K^-\pi^+$ final states. The precision is improved
relative to the previous best measurement by approximately 60%. No evidence for
$CP$ violation is found.
