Measurements of the differential cross sections of Z + jets and γ + jets production, and their ratio, are presented as a function of the boson transverse momentum. Measurements are also presented of the angular distribution between the Z boson and the closest jet. The analysis is based on pp collisions at a center-of-mass energy of 13 TeV corresponding to an integrated luminosity of 35.9 fb−1 recorded by the CMS experiment at the LHC. The results, corrected for detector effects, are compared with various theoretical predictions. In general, the predictions at higher orders in perturbation theory show better agreement with the measurements. This work provides the first measurement of the ratio of the differential cross sections of Z + jets and γ + jets production at 13 TeV, as well as the first direct measurement of Z bosons emitted collinearly with a jet.