Coherent control of quantum dynamics is key to a multitude of fundamental studies and applications. In the visible or longer-wavelength domains, near-resonant light fields have become the primary tool with which to control electron dynamics. Recently, coherent control in the extreme-ultraviolet range was demonstrated, with a few-attosecond temporal resolution of the phase control. At hard-X-ray energies (above 5–10 kiloelectronvolts), Mössbauer nuclei feature narrow nuclear resonances due to their recoilless absorption and emission of light, and spectroscopy of these resonances is widely used to study the magnetic, structural and dynamical properties of matter. It has been shown that the power and scope of Mössbauer spectroscopy can be greatly improved using various control techniques. However, coherent control of atomic nuclei using suitably shaped near-resonant X-ray fields remains an open challenge. Here we demonstrate such control, and use the tunable phase between two X-ray pulses to switch the nuclear exciton dynamics between coherent enhanced excitation and coherent enhanced emission. We present a method of shaping single pulses delivered by state-of-the-art X-ray facilities into tunable double pulses, and demonstrate a temporal stability of the phase control on the few-zeptosecond timescale. Our results unlock coherent optical control for nuclei, and pave the way for nuclear Ramsey spectroscopy and spin-echo-like techniques, which should not only advance nuclear quantum optics, but also help to realize X-ray clocks and frequency standards. In the long term, we envision time-resolved studies of nuclear out-of-equilibrium dynamics, which is a long-standing challenge in Mössbauer science.