The measurement of the production of prompt D 0 , D + , D * + , and D + s mesons in proton-lead (p-Pb) collisions at the centre-of-mass energy per nucleon pair of √ s NN = 5.02 TeV, with an integrated luminosity of 292 ± 11 µb −1 , are reported. Differential production cross sections are measured at mid-rapidity (−0.96 < y cms < 0.04) as a function of transverse momentum (p T) in the intervals 0 < p T < 36 GeV/c for D 0 , 1 < p T < 36 GeV/c for D + and D * + , and 2 < p T < 24 GeV/c for D + s mesons. For each species, the nuclear modification factor R pPb is calculated as a function of p T using a proton-proton (pp) reference measured at the same collision energy. The results are compatible with unity in the whole p T range. The average of the non-strange D mesons R pPb is compared with theoretical model predictions that include initial-state effects and parton transport model predictions. The p T dependence of the D 0 , D + , and D * + nuclear modification factors is also reported in the interval 1 < p T < 36 GeV/c as a function of the collision centrality, and the central-to-peripheral ratios are computed from the D-meson yields measured in different centrality classes. The results are further compared with charged-particle measurements and a similar trend is observed in all the centrality classes. The ratios of the p T-differential cross sections of D 0 , D + , D * + , and D + s mesons are also reported. The D + s and D + yields are compared as a function of the charged-particle multiplicity for several p T intervals. No modification in the relative abundances of the four species is observed with respect to pp collisions within the statistical and systematic uncertainties.