To address the problem of low localization accuracy in the node localization algorithms of wireless sensor networks (WSN) based on received signal strength indication (RSSI) ranging, a WSN node localization algorithm based on ranging optimization and graph optimization is proposed. In terms of RSSI ranging, the outliers are removed using the Grubbs method, and the data are processed using a moving average smoothing-Gaussian hybrid filter to establish a Bessel function ranging model to reduce the ranging error; in terms of node localization, the signal strength data are employed to construct a distance cost term, a cost function model is built based on these cost terms, and graph optimization is adopted to minimize this function. Then, the node position is estimated to minimize the overall observation error. Simulation results indicate that the proposed algorithm has higher ranging and localization accuracy than existing ranging and localization algorithms, and it can meet the requirements of node localization in large-scale WSN.