Solution (source code)

= Solution
{c}

<measurability> with respect to $\sigma(f)$ gives a <Borel set> $C_{n,k}$ with $g^{-1}(B_{n,k})=f^{-1}(C_{n,k})$. Restrict it to the actual image:
$$
\boxed{A_{n,k}=C_{n,k}\cap f(M).}
$$
This is Borel by the assumed Borel property of $f(M)$, and its <preimage> under $f$ is unchanged.

The intervals $B_{n,k}$ partition the real line, so their <preimages> under $g$ partition $M$. If two of the restricted sets overlapped, a point in their intersection would equal $f(x)$ for some $x$, making $g(x)$ lie in two disjoint intervals, a contradiction. Similarly any $t\in f(M)$ has a preimage $x$, whose real value $g(x)$ belongs to one of those intervals; that puts $t$ in the corresponding $A_{n,k}$. Thus the restricted sets are disjoint and their union is exactly $f(M)$. This restriction is what removes arbitrary overlaps of the initially chosen <Borel sets> outside the image.