$\def\rk{\operatorname{rank}}\def\im{\operatorname{im}}$If $\rk M = 0$, then $M = 0$, hence $\alpha = \beta = 0$ will work. If $\rk M = 1$, choose $x \in K^n$ with $Mx \ne 0$ and let $\alpha = Mx$. As $\dim \operatorname{im} M = 1$, we have $K\cdot \alpha = \im M$. Now let $1 \le i \le n$ and $e_i$ the $i$-th standard unit vector. Now $Me_i \in \im M$, hence there is $\beta_i \in K$ with $Me_i = \beta_i \alpha$. Let $\beta = (\beta_1, \ldots, \beta_n)^\top \in K^n$. Then we have for each $i$ \[ Me_i = \beta_i \cdot\alpha = \alpha\beta^\top e_i \] hence $M = \alpha\beta^\top$.
If we work over a ring, the condition $\rk M = 1$ tells us in the same way that $\im M$ has a generating set of size 1. If moreover our ring $R$ is a PID, we know that $\im M$, being a submodule of the free module $R^n$, is free, hence the same will work, taking as $\alpha$ a basis of $\im M$.