Gas accretion in distant galaxies as the origin of chemical abundance gradients