A low-energy adaptive clustering hierarchy (LEACH) routing protocol has been proposed specifically for wireless sensor networks (WSNs). However, in LEACH protocol the criteria for clustering and selecting cluster heads (CHs) nodes were not mentioned. In this paper, we propose to improve the LEACH protocol by combining the use of K-means algorithm for clustering and bat algorithm (BA) to select nodes as CHs. The proposed routing algorithm, called BA-LEACH, is superior to other algorithms, namely PSO-LEACH, which using particle swarm optimization (PSO) to improve LEACH. Simulation analysis shows that the BA-LEACH can obviously reduce network energy consumption and optimize the lifetime of WSNs.