In this paper, we give a barrier argument at infinity for solutions of an elliptic equation on a complete Riemannian manifold. By using the barrier argument, we can construct a nonnegative (bounded, respectively) solution of the elliptic equation, which takes the given data at infinity of each end. In particular, we prove that if a complete Riemannian manifold has finitely many ends, each of which is Harnack and nonparabolic, then the set of bounded solutions of the elliptic equation is finite dimensional, in some sense. We also prove that if a complete Riemannian manifold is roughly isometric to a complete Riemannian manifold satisfying the volume doubling condition, the Poincaré inequality and the finite covering condition on each end, then there exists a nonnegative solution of an elliptic equation taking the given data at infinity of each end of the manifold. These results generalize those of Yau, of Donnelly, of Grigor'yan, of Li and Tam, of Holopainen, and of the present authors, but with the barrier argument at infinity that enables one to overcome the obstacle due to the nonlinearity of solutions.