This paper addresses the distributed observer-based consensus problem of second-order multi-agent systems via sampled data. Firstly, for the case of fixed topology, a velocity-independent distributed control law is proposed by designing a distributed observer to estimate the unavailable velocity, then a sufficient and necessary condition of consensus on design parameters and sampling period is obtained by using the matrix analysis method. Secondly, for the case of stochastically switching topology, a sufficient and necessary condition of mean square consensus is also proposed and proven, and an algorithm is provided to design the parameters in the consensus protocol. Two simulation examples are given to illustrate the effectiveness of the proposed consensus algorithms. Copyright © 2012 John Wiley & Sons, Ltd.