Measurements of open charm and beauty production cross sections in deep inelastic ep scattering at HERA from the H1 and ZEUS Collaborations are combined. Reduced cross sections are obtained in the kinematic range of negative four-momentum transfer squared of the photon 2.5 GeV2≤Q2≤2000GeV2 and Bjorken scaling variable 3⋅10−5≤xBj≤5⋅10−2 . The combination method accounts for the correlations of the statistical and systematic uncertainties among the different datasets. Perturbative QCD calculations are compared to the combined data. A next-to-leading order QCD analysis is performed using these data together with the combined inclusive deep inelastic scattering cross sections from HERA. The running charm- and beauty-quark masses are determined as mc(mc)=1.290+0.046−0.041(exp/fit) +0.062−0.014(model) +0.003−0.031(parameterisation) GeV and mb(mb)=4.049+0.104−0.109(exp/fit) +0.090−0.032(model) +0.001−0.031(parameterisation) GeV .