Russia and Ukraine clinched a transit agreement for gas deliveries to Europe, warding off massive disruptions in the new year and securing steady supplies, even as U.S. sanctions temporarily halted work on a new gas pipeline from Russia to Germany.

Officials from Ukraine and Russia’s state-run energy giant PAO Gazprom unveiled details of their five-year contract on Saturday, after crunch talks and last-minute compromises by Moscow and Kyiv led to a protocol late Friday. The new contract, to take effect Jan. 1, will replace...