Using proton-proton collision data, corresponding to an integrated luminosity of 9 fb−1, collected with the LHCb detector between 2011 and 2018, a new narrow charmonium state, the X(3842) resonance, is observed in the decay modes X (3842) → DD¯ and X(3842) → D+D−. The mass and the natural width of this state are measured to be mX(3842)=3842.71±0.16±0.12MeV/c2,ΓX(3842)=2.79±0.51±0.35MeV, where the first uncertainty is statistical and the second is systematic. The observed mass and narrow natural width suggest the interpretation of the new state as the unobserved (spin-3 ψ3 13D3) charmonium state. In addition, prompt hadroproduction of the ψ(3770) and χ2(3930) states is observed for the first time, and the parameters of these states are measured to be mψ(3770)=3778.1±0.7±0.6MeV/c2,mχ2(3930)=3921.9±0.6±0.2MeV/c2,Γχ2(3930)=36.6±1.9±0.9MeV, where the first uncertainty is statistical and the second is systematic.[Figure not available: see fulltext.].