Purely by definition, as @Magdiragdag pointed out.
But beware: the subtlety here is that polynomials and polynomials functions are not necessarily the same thing!
Polynomials can be turned into functions if you "plug in" values for X. But if the values for X lies in a finite field then it can happen that different polynomials give rise to the same polynomial function!
For example, take the field $Z_2 = \{0,1\}$ of residues mod 2, then $X^2$ and $X$ are different polynomials in $Z_2[X]$ (they have different coefficients) but the corresponding polynomial functions are the same, since $X^2 = X$ for $X = 0$ and $1$. More generally, the different polynomials $X^p$ and $X$ give rise to the same polynomial function for $X$ lying in the field $Z_p$ of residues mod p (p a prime), as an immediate consequence of Fermat's Little Theorem.
To go on with your argument and conclude that $a_1 = b_1$ in the polynomials seen as polynomial functions over R you must be able to choose a nonzero X in the field R which is not a root of neither $a_n X^{n−1}+\cdots+a_1$, nor $b_n X^{n−1}+\cdots+b_1$, which you can do safely if your ring R is an infinite field, such as the rationals, the reals or the complex numbers.
So, following your proof, for infinite fields R we get that polynomials in R[X] and polynomials functions with domain R are "the same thing". But this is not true for an arbitrary ring R, as the examples above point out.