Three-jet production in the reaction ep --> eXp has been studied with the ZEUS detector at HERA using an integrated luminosity of 42.74 pb^-1. The data were measured in the kinematic region 5 < Q^2 < 100 GeV^2, 200 < W < 250 GeV and 23 < M_X < 40 GeV. The diffractive signal was selected by requiring a large rapidity gap in the outgoing proton direction. Jets were reconstructed in the centre-of-mass system of X using the exclusive k_T-algorithm. A sample of three-jet events in diffraction has been identified. Differential cross sections were measured as a function of the jet pseudorapidity and jet transverse momentum with respect to the virtual photon-Pomeron axis. The jets going in the Pomeron direction are broader than those going in the virtual-photon direction. This is consistent with models predicting that gluons are predominantly produced in the Pomeron direction and quarks in the virtual-photon direction.