With the H1 detector at the ep collider HERA, D∗ meson production cross sections have been measured in deep inelastic scattering with four-momentum transfers Q2>2 GeV2 and in photoproduction at energies around Wγp∼88 GeV and 194 GeV. Next-to-Leading Order QCD calculations are found to describe the differential cross sections within theoretical and experimental uncertainties. Using these calculations, the NLO gluon momentum distribution in the proton, xgg(xg), has been extracted in the momentum fraction range 7.5×10−4<xg<4×10−2 at average scales mu2=25 to 50 GeV2. The gluon momentum fraction xg has been obtained from the measured kinematics of the scattered electron and the D∗ meson in the final state.