A detailed analysis is presented of the diffractive deep-inelastic scattering process ep → eXY , where Y is a proton or a low mass proton excitation carrying a fraction 1−x I P > 0.95 of the incident proton longitudinal momentum and the squared four-momentum transfer at the proton vertex satisfies |t| < 1 GeV 2 . Using data taken by the H1 experiment, the cross section is measured for photon virtualities in the range 3.5 ≤ Q 2 ≤ 1600 GeV 2 , triple differentially in x I P , Q 2 and β = x/x I P , where x is the Bjorken scaling variable. At low x I P , the data are consistent with a factorisable x I P dependence, which can be described by the exchange of an effective pomeron trajectory with intercept α IP (0) = 1.118 ± 0.008 (exp.) +0.029 −0.010 (model). Diffractive parton distribution functions and their uncertainties are determined from a next-to-leading order DGLAP QCD analysis of the Q 2 and β dependences of the cross section. The resulting gluon distribution carries an integrated fraction of around 70% of the exchanged momentum in the Q 2 range studied. Total and differential cross sections are also measured for the diffractive charged current process e + p →ν e XY and are found to be well described by predictions based on the diffractive parton distributions. The ratio of the diffractive to the inclusive neutral current ep cross sections is studied. Over most of the kinematic range, this ratio shows no significant dependence on Q 2 at fixed x I P and x or on x at fixed Q 2 and β.