To address the problem of transmission energy consumption and premature node death in wireless sensor networks (WSN), a novel routing strategy by IWOA that optimizes the K-means (KM) is proposed. WOA is improved by using it to optimize the KM algorithm, and more evenly distributed and suitable cluster centers are selected as the initial cluster heads (CH). In the CH election process, a CH election function is established, and the optimal CH under the influence of multiple factors is obtained. The simulation results have verified the feasibility of the proposed scheme in this paper.