  Let $H$ be a $k$-uniform hypergraph on $n$ vertices where $n$ is a
sufficiently large integer not divisible by $k$. We prove that if the minimum
$(k-1)$-degree of $H$ is at least $\lfloor n/k \rfloor$, then $H$ contains a
matching with $\lfloor n/k\rfloor$ edges. This confirms a conjecture of R\"odl,
Ruci\'nski and Szemer\'edi, who proved that the minimum $(k-1)$-degree
$n/k+O(\log n)$ suffices. More generally, we show that $H$ contains a matching
of size $d$ if its minimum codegree is $d<n/k$, which is also best possible.
