  We present a determination of the Cabibbo-Kobayashi-Maskawa matrix elements
$|V_{cd}|$ and $|V_{cs}|$ obtained by combining the momentum dependence of the
semileptonic vector form factors $f_+^{D \to \pi}(q^2)$ and $f_+^{D \to
K}(q^2)$, recently determined from lattice QCD simulations, with the
differential rates measured for the semileptonic $D \to \pi \ell \nu$ and $D
\to K \ell \nu$ decays. Our analysis is based on the results for the
semileptonic form factors produced by the European Twisted Mass Collaboration
with $N_f = 2 + 1 + 1$ flavors of dynamical quarks in the whole range of values
of the squared 4-momentum transfer accessible in the experiments. The
statistical and systematic correlations between the lattice data as well as
those present in the experimental data are properly taken into account. With
respect to the standard procedure based on the use of only the vector form
factor at zero 4-momentum transfer, we obtain more precise and consistent
results: $|V_{cd} |= 0.2341 ~ (74)$ and $|V_{cs} |= 0.970 ~ (33)$. The
second-row CKM unitarity is fulfilled within the current uncertainties:
$|V_{cd}|^2 + |V_{cs}|^2 + |V_{cb}|^2 = 0.996 ~ (64)$. Moreover, using for the
first time hadronic inputs determined from first principles, we have calculated
the ratio of the semileptonic $D \to \pi(K)$ decay rates into muons and
electrons, which represent a test of lepton universality within the SM,
obtaining in the isospin-symmetric limit of QCD: ${\cal{R}}_{LU}^{D\pi} =
0.985~(2)$ and ${\cal{R}}_{LU}^{DK} = 0.975~(1)$.
