We present a scheme to perform an iterative variational optimization with infinite projected entangled-pair states (iPEPS), a tensor network ansatz for a two-dimensional wave function in the thermodynamic limit, to compute the ground state of a local Hamiltonian. The method is based on a systematic summation of Hamiltonian contributions using the corner transfer-matrix method. Benchmark results for challenging problems are presented, including the 2D Heisenberg model, the Shastry-Sutherland model, and the t-J model, which show that the variational scheme yields considerably more accurate results than the previously best imaginary time evolution algorithm, with a similar computational cost and with a faster convergence towards the ground state.