Let $R$ be an integral domain, $K$ its field of fractions and $A$ a (unital, associative) $K$-algebra of finite dimension. Call $a \in A$ integral (over $R$) if it is a root of a monic polynomial with coefficients in $R$.
(When) does this imply that the trace of $a$ (trace of the linear map $x \mapsto ax$) lies in $R$?
It is certainly true if $R$ is a PID: take any finitely generated $R$-submodule $M \subset A$ that is stable by $a$ and generates $A$ over $K$. (E.g.: take any free $R$-submodule $N$ that generates $A$ over $K$ and take $M = R[a] N$.) Because $R$ is a PID, it is free, necessarily of rank $\dim_K A$ and one can then compute the trace of $A$ w.r.t. a basis of $M$.
In the general case, it would suffice to find a free $R$-submodule that is stable by $a$ and generates $A$ over $K$. I don't know if that exists.
The trace of $a$ is always integral over $R$.
Indeed, pick any basis $\left(b_1,b_2,\ldots,b_n\right)$ of the finite-dimensional $K$-vector space $A$. Let $L_a : A \to A$ be the $K$-linear map sending each $b \in A$ to $ab$. This map $L_a$ is an endomorphism of the $K$-vector space $A$, and thus can be represented by a square matrix over $K$ (with respect to the basis $\left(b_1,b_2,\ldots,b_n\right)$). Let $M_a$ be this matrix. Of course, the trace of $a$ equals the trace of $L_a$ (by definition), which in turn equals the trace of $M_a$ (by definition).
The matrix $M_a$ is integral over $R$ (since the same monic polynomial over $R$ that annihilates $a$ will annihilate $L_a$ and thus annihilate $M_a$). It thus remains to prove that if a matrix over $K$ is integral over $R$, then so is its trace. But this is a particular case of Corollary 1.26 in