This paper is mainly devoted to a distributed iterative learning control design for a class of nonlinear discrete-time multi-agent systems in the presence of randomly varying iteration lengths. A stochastic variable is introduced and utilized to construct a consensus error with iteration-varying lengths. The distributed ILC law using the consensus error term is considered, contraction mapping and λ-norm technique methods are employed to develop a sufficient condition for the asymptotic stability of ILC. It is shown that all agents can be guaranteed to achieve finite-time tracking with randomly varying iteration lengths, even under the condition that the desired trajectory is available to not all, but only a portion of agents. The proposed algorithm is also extended to achieve consensus control for switching topologies multi-agent systems with iteration-varying lengths. Two illustrative examples are given to demonstrate the effectiveness of the theoretical results. INDEX TERMS Multi-agent systems (MAS), consensus tracking, randomly length varying, iterative learning control (ILC), convergence.