Cancellation property for commutative monoid

The answer is no. Let $U=\{0,1\}$ under multiplication. Let $P$ be the semigroup of positive integers under $+$. Consider $S=P\times U$, the direct product and let $M=S\cup \{I\}$ where $I$ is an adjoined identity. Then $M$ is torsion-free, there is a homomorphism $f\colon \mathbf N\to M$ given by $f(0)=I$ and $f(n)=(n,0)$ for $n>0$ and $g\colon M\to \mathbf N$ with $g(I)=0$ and $g(n,x)=n$ for $n>0$ and $x\in \{0,1\}$ and clearly $gf=1$ but $(1,0)$ is not cancellable.


Consider the monoid $M=\mathbb{N}\times \{0,1\}$ where $$(n,a)*(m,b):=(n+m, a\cdot b).$$ The unit element is $e:=(0,1)$. Note that this monoid is torsion free. Now consider the maps $$g:(M,*,e)\rightarrow (\mathbb{N}, +,0), g(n,a)=n$$ and $f: (\mathbb{N}, +,0) \rightarrow (M,*,e)$ such that $f(0)=e$ and $f(n)=(n,0)$. Then we have $g\circ f=id$, but $f(1)=(1,0)$ is not cancellative as $$ (1,0)*(0,0)=(1,0)=(1,0)*(0,1).$$