The proof of @user91684 is a shadow of a larger phenomenon!
Let $\mathcal{C}$ be an abelian category.
Definition: We say that an object V is simple if for every other object W and any Hom, $f: V \to W$ we have that either $f$ is the zero map or that it is a monomorphism
Lemma: Let $g: V \to V$ be a map such that $Im(g)$ is simple. Then for any maps $f: U \to V, h: V \to W$ such that $h \circ g \circ f = 0$, we have that either $g \circ f = 0$ or $h \circ g = 0$.
Proof: Write $g = m \circ e$, where $m: Im (g) \to V$ is mono and $e: V \to Im(g)$ is epi. Then we have that by the hypothesis $(h \circ m) \circ (e \circ f) = 0$. Suppose that $h \circ m = 0$ then $h \circ g = 0$ and we're done. Else, since it's a non zero map from a simple object we have that $h \circ m$ is a mono. Thus from the hypothesis, $e \circ f = 0$.
Now we note that on setting $\mathcal{C}$ to be the category of vector spaces, $V = \mathbb{F}^n$, $g = AB - BA$, $f$ to be the inclusion map of $\ker(A)$ into $V$, and $h$ to be the map from $V$ onto $\mathrm{coker}(A)$, we have that from a tautological calculation.
$$
h \circ g \circ f = 0
$$
But our hypothesis is that the rank of $g$ is at most one, i.e it's image is a simple object in the category of vector spaces
Thus, we get that either $h \circ g = 0$ or that $g \circ f = 0$. The former is equivalent to $B(Im (A)) \subset Im(A)$ and the latter is equivalent to $B(\ker(A)) \subset \ker(A)$.
Now if $\mathbb{F}$ is algebraically closed we can plug into $A$ an $A-\lambda I_n$ where $\ker(A-\lambda I_n)$ is non zero. By induction on the dimension of the space that $A,B$ act on, we're done.