[proofplan]
We fix a finite generating set $\{m_1, \dots, m_n\}$ for $M$ and express the condition $f(M) \subseteq \mathfrak{a}M$ as a matrix equation $f(m_i) = \sum_j p_{ij} m_j$ with $p_{ij} \in \mathfrak{a}$. We then make $M$ into an $R[T]$-module by letting $T$ act as $f$, rewrite the matrix equation as $(TI_n - P)m = 0$ in the $R[T]$-module $M^n$, and apply the adjugate trick: left-multiplying by $\operatorname{adj}(TI_n - P)$ yields $\det(TI_n - P) \cdot m_i = 0$ for each $i$, whence $\det(TI_n - P)$ annihilates all of $M$. Expanding this determinant produces the desired monic polynomial relation with coefficients in $\mathfrak{a}$.
[/proofplan]
[step:Express $f(m_i)$ as an $\mathfrak{a}$-linear combination of the generators]
Let $\{m_1, \dots, m_n\}$ be a finite generating set for $M$ (such a set exists since $M$ is finitely generated). Since $f(M) \subseteq \mathfrak{a}M$ and every element of $\mathfrak{a}M$ is a finite sum $\sum_j a_j m_j$ with $a_j \in \mathfrak{a}$, for each $1 \leq i \leq n$ there exist elements $p_{ij} \in \mathfrak{a}$ such that
\begin{align*}
f(m_i) = \sum_{j=1}^{n} p_{ij}\, m_j.
\end{align*}
Define the matrix $P := (p_{ij}) \in M_{n \times n}(R)$. All entries of $P$ lie in $\mathfrak{a}$.
[guided]
The hypothesis $f(M) \subseteq \mathfrak{a}M$ means that $f$ maps every element of $M$ into $\mathfrak{a}M$, the submodule of $M$ consisting of all finite $\mathfrak{a}$-linear combinations of elements of $M$. In particular, each $f(m_i) \in \mathfrak{a}M$. Since $\{m_1, \dots, m_n\}$ generates $M$, every element of $\mathfrak{a}M$ can be written as $\sum_j a_j m_j$ with $a_j \in \mathfrak{a}$ (because any $m \in M$ is itself an $R$-linear combination of the $m_j$, and multiplying by an element of $\mathfrak{a}$ keeps the coefficients in $\mathfrak{a}$). So we can express each $f(m_i)$ as such a combination, with the coefficients $p_{ij}$ lying in $\mathfrak{a}$.
The matrix $P$ encodes the action of $f$ on the generators. It is not the matrix of $f$ in the usual linear algebra sense (the $m_i$ need not be a basis — $M$ need not be free), but it records enough information to extract a polynomial relation.
[/guided]
[/step]
[step:Make $M$ into an $R[T]$-module by letting $T$ act as $f$]
The $R$-algebra $\operatorname{End}_R(M)$ contains the identity $\operatorname{id}_M$ and is closed under composition. By the [Universal Property of Polynomial Algebra](/theorems/2820) applied with $n = 1$ and $a_1 = f$, there is a unique $R$-algebra homomorphism
\begin{align*}
\operatorname{ev}_f: R[T] &\to \operatorname{End}_R(M) \\
T &\mapsto f.
\end{align*}
This makes $M$ into an $R[T]$-module by defining $T \cdot m := f(m)$ for $m \in M$. More generally, for a polynomial $q(T) = \sum_k c_k T^k \in R[T]$, the action is $q(T) \cdot m = \sum_k c_k f^k(m)$.
The matrix equation from the previous step can now be rewritten. For each $i$,
\begin{align*}
f(m_i) - \sum_{j=1}^{n} p_{ij}\, m_j = 0,
\end{align*}
which in the $R[T]$-module $M$ reads
\begin{align*}
T \cdot m_i - \sum_{j=1}^{n} p_{ij}\, m_j = 0, \qquad \text{i.e.,} \qquad \sum_{j=1}^{n} (T\delta_{ij} - p_{ij})\, m_j = 0,
\end{align*}
where $\delta_{ij}$ is the Kronecker delta. In matrix form over $R[T]$:
\begin{align*}
(TI_n - P) \begin{pmatrix} m_1 \\ \vdots \\ m_n \end{pmatrix} = \begin{pmatrix} 0 \\ \vdots \\ 0 \end{pmatrix}.
\end{align*}
[guided]
The idea of making $M$ into an $R[T]$-module is a powerful algebraic device. Instead of reasoning about the endomorphism $f$ and its powers directly, we encode everything into the module structure. The polynomial $T$ acts as $f$, so $T^2$ acts as $f^2$, and so on. A polynomial equation $q(T) = 0$ in $\operatorname{End}_R(M)$ then corresponds to $q(T) \cdot m = 0$ for all $m \in M$.
The rewriting of the matrix equation is straightforward: $f(m_i) = T \cdot m_i$ in the $R[T]$-module, so $f(m_i) - \sum_j p_{ij} m_j = 0$ becomes $\sum_j (T\delta_{ij} - p_{ij}) m_j = 0$. The matrix $Q := TI_n - P$ has entries in $R[T]$ (specifically, the diagonal entries are $T - p_{ii}$ and the off-diagonal entries are $-p_{ij}$).
[/guided]
[/step]
[step:Apply the adjugate to show $\det(TI_n - P)$ annihilates each generator $m_i$]
Let $Q := TI_n - P \in M_{n \times n}(R[T])$. The adjugate (classical adjoint) of $Q$ is the matrix $\operatorname{adj}(Q) \in M_{n \times n}(R[T])$ defined by $\operatorname{adj}(Q)_{ij} = (-1)^{i+j} \det(Q_{ji})$, where $Q_{ji}$ is the $(j,i)$-minor of $Q$. The fundamental identity for the adjugate over any commutative ring states
\begin{align*}
\operatorname{adj}(Q) \cdot Q = (\det Q) \cdot I_n.
\end{align*}
Left-multiplying the equation $Q m = 0$ (where $m = (m_1, \dots, m_n)^\top$) by $\operatorname{adj}(Q)$ gives
\begin{align*}
(\det Q) \cdot I_n \cdot m = \operatorname{adj}(Q) \cdot (Q m) = \operatorname{adj}(Q) \cdot 0 = 0.
\end{align*}
Reading component by component, $(\det Q) \cdot m_i = 0$ for each $1 \leq i \leq n$.
[guided]
The adjugate trick is the core of the argument. In ordinary linear algebra over a field, $\operatorname{adj}(Q) \cdot Q = (\det Q) I_n$ is a standard identity. The crucial point is that this identity holds over any commutative ring — it is a polynomial identity in the entries of $Q$, valid because it can be verified over $\mathbb{Z}[x_{ij}]$ and then specialised. No invertibility or field assumptions are needed.
The multiplication $\operatorname{adj}(Q) \cdot Qm$ takes place in the $R[T]$-module $M^n$ (column vectors with entries in $M$). Since $Qm = 0$, we get $(\det Q) I_n m = 0$, i.e., $(\det Q) \cdot m_i = 0$ for each $i$. Here $\det Q \in R[T]$ and the action of $R[T]$ on $M$ is via $\operatorname{ev}_f$.
[/guided]
[/step]
[step:Show $\det(TI_n - P)$ annihilates all of $M$ and extract the polynomial relation]
Since $(\det Q) \cdot m_i = 0$ for each generator $m_i$ and the action of $R[T]$ on $M$ is $R$-linear, for any $m \in M$ we write $m = \sum_{i=1}^n r_i m_i$ with $r_i \in R$ and compute
\begin{align*}
(\det Q) \cdot m = \sum_{i=1}^n r_i \bigl((\det Q) \cdot m_i\bigr) = 0.
\end{align*}
Hence $\det Q$ acts as the zero endomorphism on $M$, i.e., $\operatorname{ev}_f(\det Q) = 0$ in $\operatorname{End}_R(M)$.
We now expand $\det Q = \det(TI_n - P)$. This is a polynomial in $T$ of degree $n$. By the Leibniz formula for the determinant,
\begin{align*}
\det(TI_n - P) = \sum_{\sigma \in S_n} \operatorname{sgn}(\sigma) \prod_{i=1}^n (TI_n - P)_{i,\sigma(i)}.
\end{align*}
The only permutation $\sigma$ that contributes a degree-$n$ term in $T$ is the identity $\sigma = \operatorname{id}$, which gives $\prod_{i=1}^n (T - p_{ii}) = T^n + (\text{lower-order terms})$. Every other permutation $\sigma \neq \operatorname{id}$ involves at least one off-diagonal factor $-p_{i,\sigma(i)}$ in place of a diagonal factor $T - p_{ii}$, reducing the degree below $n$. Therefore $\det(TI_n - P)$ is a monic polynomial of degree $n$:
\begin{align*}
\det(TI_n - P) = T^n + a_1 T^{n-1} + \dots + a_n
\end{align*}
for some $a_1, \dots, a_n \in R$.
[guided]
Why is the determinant monic of degree $n$? The matrix $TI_n - P$ has the diagonal entries $T - p_{ii}$ and off-diagonal entries $-p_{ij} \in \mathfrak{a}$. In the Leibniz expansion, the identity permutation contributes
\begin{align*}
\prod_{i=1}^n (T - p_{ii}) = T^n - \left(\sum_i p_{ii}\right) T^{n-1} + \cdots + (-1)^n \prod_i p_{ii}.
\end{align*}
Any non-identity permutation $\sigma$ has at least one index $i$ with $\sigma(i) \neq i$, so the product $\prod_i (TI_n - P)_{i,\sigma(i)}$ includes the off-diagonal entry $-p_{i,\sigma(i)}$ (a constant in $R$) instead of the linear factor $T - p_{ii}$. This reduces the degree of $T$ in that product by at least one, so the contribution has degree at most $n-1$. Hence the leading term $T^n$ comes only from $\sigma = \operatorname{id}$, making the determinant monic.
[/guided]
[/step]
[step:Verify the coefficients lie in $\mathfrak{a}$ and state the conclusion]
We show $a_k \in \mathfrak{a}$ for each $1 \leq k \leq n$. Every entry of the matrix $P$ lies in $\mathfrak{a}$. In the Leibniz expansion, the identity permutation contributes $\prod_{i=1}^n (T - p_{ii})$. Expanding this product, the coefficient of $T^{n-k}$ is $(-1)^k e_k(p_{11}, \dots, p_{nn})$, where $e_k$ denotes the $k$-th elementary symmetric polynomial. Since each $p_{ii} \in \mathfrak{a}$ and $\mathfrak{a}$ is an ideal, every monomial in $e_k(p_{11}, \dots, p_{nn})$ is a product of $k$ elements of $\mathfrak{a}$, hence lies in $\mathfrak{a}^k \subseteq \mathfrak{a}$. For a non-identity permutation $\sigma$, the product $\prod_i (TI_n - P)_{i,\sigma(i)}$ involves at least one off-diagonal entry $-p_{i,\sigma(i)} \in \mathfrak{a}$. Each term of the expansion is therefore a product of ring elements at least one of which lies in $\mathfrak{a}$, so each such product lies in $\mathfrak{a}$. Thus every coefficient $a_k$ of $T^{n-k}$ in $\det(TI_n - P)$ belongs to $\mathfrak{a}$.
Since $\operatorname{ev}_f(\det Q) = 0$ in $\operatorname{End}_R(M)$ and $\operatorname{ev}_f(T^k) = f^k$, we obtain
\begin{align*}
f^n + a_1 f^{n-1} + \dots + a_n \operatorname{id}_M = 0
\end{align*}
in $\operatorname{End}_R(M)$, with $a_1, \dots, a_n \in \mathfrak{a}$, as required.
[guided]
The coefficients lie in $\mathfrak{a}$ because every term in the determinant expansion involves entries of $P$ (which are in $\mathfrak{a}$) or factors of $T$. More precisely, the coefficient of $T^{n-k}$ (for $k \geq 1$) in the full determinant expansion is a sum of products, each containing at least $k$ entries from $P$ (and possibly some diagonal entries $-p_{ii}$). Since each such entry lies in $\mathfrak{a}$ and $\mathfrak{a}$ is an ideal, the product lies in $\mathfrak{a}^k \subseteq \mathfrak{a}$, and the sum lies in $\mathfrak{a}$.
The case $k = 0$ gives the leading coefficient $1$ (the coefficient of $T^n$), confirming the polynomial is monic.
The final substitution $T \mapsto f$ via the evaluation homomorphism $\operatorname{ev}_f$ converts the polynomial identity $\det(TI_n - P) = 0$ in $\operatorname{End}_R(M)$ (established by the adjugate argument) into the explicit relation $f^n + a_1 f^{n-1} + \dots + a_n \operatorname{id}_M = 0$.
[/guided]
[/step]