In this paper, the robust output consensus problem for a class of heterogeneous linear multiagent systems (MASs) in presence of aperiodic sampling and random deny-of-service (DoS) attack is investigated. A novel distributed output-feedback control strategy is proposed so that the controlled MAS achieves the objective of output consensus in spite of aperiodic sampling and DoS attack. By assuming that the sampling process is nonuniform and the consecutive attack duration is upper bounded, the closed-loop control system is first described as a discrete-time switched stochastic delay system. Some sufficient conditions are then obtained for the solvability of the secure consensus problem. Furthermore, a constructive design procedure for the proposed controller is then presented. Finally, a simulation example is introduced to illustrate the effectiveness of controller design.