Episodic magmatic degassing has been observed at numerous volcanoes, especially those of intermediate composition. It can span timescales from years to decades. Here we propose a physical model for the degassing of a shallow magma intrusion to explain this phenomenon. The magma cools by convection, which leads to melt crystallization, volatile exsolution, and magma overpressure. When the pressure reaches a critical value, wall rocks fracture and the exsolved gas escapes. The intrusion then returns to the initial lithostatic pressure and a new cooling-crystallization-degassing cycle occurs. A series of such cycles leads to episodic degassing. The trend and timescale of the degassing process are mainly governed by magma cooling. Two degassing regimes are exhibited: an early phase with a high frequency of gas pulses and a later phase with a lower gas pulse frequency. The transition between these two regimes is caused by the viscosity increase when the magma crystallinity exceeds the crystal percolation threshold. We find that the time to this transition is dependent on magma volume, to a first approximation. Where observations are available from sustained geochemical surveillance, the model provides constraints on key aspects of the subsurface magmatic system, with estimation of the volume of an intrusion and tensile strength of the surrounding rocks. It therefore represents a relevant tool for volcanic surveillance and hazard assessment.