Oil swung between gains and losses as Russia’s war against Ukraine escalated while Iran agreed to stop producing uranium enriched close to the level at which it can be used in nuclear weapons.