A scheme for efficient correction of driving-field frequency drifts in Ramsey interferometry is proposed. The two off-resonant $\ensuremath{\pi}/2$ pulses of duration $T$ used in the traditional Ramsey setup are supplemented with an additional pulse of duration $2T$ (approximate $\ensuremath{\pi}$ pulse), which is applied midway between the Ramsey pulses and has a detuning of opposite sign to theirs. This scheme, which resembles a Hahn's spin-echo pulse embedded into the Ramsey setup, corrects small-to-moderate random errors in the detuning of the driving field. This allows the observation of Ramsey fringes of high contrast even with a noisy driving field or in inhomogeneously broadened atomic ensembles. The contrast is further improved by replacing the refocusing $2T$ pulse by a composite $\ensuremath{\pi}$ pulse. We demonstrate the validity of the concept by comparing experimental results from usual Ramsey measurements with Hahn-Ramsey measurements. These experimental results are obtained from microwave-optical double-resonance spectroscopy on $^{171}\mathrm{Yb}{}^{+}$ ions in a segmented linear Paul trap. In the same way, we verify qualitatively the predicted advantage from using a composite $\ensuremath{\pi}$ pulse for refocusing.