Yes, this is true: by Exercise 13.5 in Kechris' "Classical Descriptive Set Theory", for any Borel function $f:X\to Y$ between Polish spaces there exists a continuous bijective map $i:Z\to X$ from a Polish space $Z$ such that the function $f\circ i:Z\to Y$ is continuous. Consider
Now consider the function $g:X\to Y\times Z$, $g:x\mapsto (f(x),i^{-1}(x))$ and observe that it has closed graph $$\Gamma=\{(x,y,z)\in X\times Y\times Z:y=f(x),\; x=i(z)\}=\{(x,y,z)\in X:y=f\circ i(z),\;x=i(z)\}$$by the continuity of the functions $i$ and $f\circ i$. It is clear that $f=\pi_Y\circ g$.