Let $K$ be a number field of degree $n$ with ring of integers $O_K$. We show that, if $h\in K[X]$ maps every element of $O_K$ of degree $n$ to an algebraic integer, then $h(X)$ is integral-valued over $O_K$, that is $h(O_K)\subset O_K$. We also prove that a similar property holds for a polynomial $f\in\mathbb{Q}[X]$ when we consider the set of all algebraic integers $\alpha$ of degree $n$: if $f(\alpha)$ is integral over $\Z$ for every such an $\alpha$, then $f(\beta)$ is integral over $\Z$ for every algebraic integer $\beta$ of degree smaller than $n$. The result is established by proving that the ring of integer-valued polynomials over the set of matrices $M_n(\mathbb{Z})$ has integral closure equal to the ring of polynomials in $\mathbb{Q}[X]$ which are integral-valued over the set of algebraic integers of degree equal to $n$.