We compute the helicity amplitudes for the processes $gg\to Zg$ and $gg\to Z\gamma$ to two loops in massless QCD. The perturbative expansion of these processes starts only at the one-loop level, such that our results are a crucial ingredient to the NLO corrections to $Z\gamma$ and $Z+$jet production through gluon fusion.