Purpose Large-scale optimization tasks have many applications in science and engineering. There are many algorithms to perform such optimization tasks. In this manuscript, we aim at using consensus in multi-agent systems as a tool for solving large-scale optimization tasks. Method The model is based on consensus of opinions among agents interacting over a complex networked structure. For each optimization task, a number of agents are considered, each with an opinion value. These agents interact over a networked structure and update their opinions based on their best-matching neighbor in the network. A neighbor with the best value of the objective function (of the optimization task) is referred to as the best-matching neighbor for an agent. We use structures such as pure random, small-world and scale-free networks as interaction graph. The optimization algorithm is applied on a number of benchmark problems and its performance is compared with a number of classic methods including genetic algorithms, differential evolution and particle swarm optimization. Results We show that the agents could solve various large-scale optimization tasks through collaborating with each other and getting into consensus in their opinions. Furthermore, we find pure random topology better than small-world and scale-free topologies in that it leads to faster convergence to the optimal solution. Our experiments show that the proposed consensus-based optimization method outperforms the classic optimization algorithms. Conclusion Consensus in multi-agents systems can be efficiently used for large-scale optimization problems. Connectivity structure of the consensus network is effective in the convergence to the optimum solution where random structures show better performance as compared to heterogeneous networks.