Expulsion of a plasmoid from a spatially nonuniform magnetic field