Theorem. Let $R$ be a commutative ring with unity, let $g(x)\in R[x]$ be a polynomial with leading coefficient a unit, and let $f(x)\in R[x]$. Then there exist polynomials $q(x),r(x)\in R[x]$ such that $f(x)=q(x)g(x) + r(x)$, and either $r=0$ or $\deg(r)\lt \deg(g)$.
Proof. If $f=0$, then there is nothing to do. Otherwise, we do induction on $\deg(f)$. Assume the result holds for any polynomial of degree smaller than $f(x)$. Let $f(x) = a_nx^n + \cdots + a_0$, and write $g(x) = b_mx^m+\cdots + b_0$. If $n\lt m$, then set $q(x)=0$, $r(x)=f(x)$, and we are done. Otherwise, note that since $b_m$ is a unit, then
$a_nb_m^{-1}\in R$, so $a_nb_m^{-1}x^{n-m}g(x)\in R[x]$. Note that the leading term of this polynomial equals that of $f(x)$, so $f(x) - a_nb_m^{-1}x^{n-m}g(x)$ is either $0$, or has degree strictly smaller than $f(x)$. Either way, we can write
$$f(x) - a_nb_m^{-1}x^{n-m}g(x) = q'(x)g(x) + r(x)$$
with $q'(x),r(x)\in R[x]$, and $r=0$ or $\deg(r)\lt \deg(g)$, by the induction hypothesis. Setting $q(x) = a_nb_m^{-1}x^{n-m}+q'(x)$ gives the desired conclusion. $\Box$
Because the leading coefficient of $g(x)$ is a unit in $A[x]$, you can perform long division and write $f(x) = q(x)g(x)+r(x)$ with $q(x)\in A[x]$, $r(x)\in A[x]$, and either $r(x)=0$ or $\deg(r)\lt\deg(g)$.
In $A[X]$ this expression may not be unique; however, since $K$ is a field, the division algorithm together with its uniqueness clause does hold; since you have found an expression for $f(x)$ as $f(x) = q(x)g(x)+r(x)$ with $q(x),r(x)\in A[x]\subseteq K[x]$ and $r(x)$ satisfies the degree conditions to be the remainder when dividing $f$ by $g$, then...