The shortage of water stands as a global challenge, prompting considerable focus on the management of water consumption and irrigation. The suggestion is to introduce a smart irrigation system based on wireless sensor networks (WSNs) aimed at minimizing water consumption while maintaining the quality of agricultural crops. In WSNs deployed in smart irrigation, accurately determining the locations of sensor nodes is crucial for efficient monitoring and control. However, in many cases, the exact positions of certain sensor nodes may be unknown. To address this challenge, this paper presents a new localization method for localizing unknown sensor nodes in WSN-based smart irrigation systems using estimated range measurements. The proposed method can accurately determine the positions of unknown nodes, even when they are located at a distance from anchors. It utilizes the Levenberg–Marquardt (LM) optimization algorithm to solve a nonlinear least-squares problem and minimize the error in estimating the unknown node locations. By leveraging the known positions of a subset of sensor nodes and the inexact distance measurements between pairs of nodes, the localization problem is transformed into a nonlinear optimization problem. To validate the effectiveness of the proposed method, extensive simulations and experiments were conducted. The results demonstrate that the proposed method achieves accurate localization of the unknown sensor nodes. Specifically, it achieves 19% and 58% improvement in estimation accuracy when compared to distance vector-hop (DV-Hop) and semidefinite relaxation-LM (SDR-LM) algorithms, respectively. Additionally, the method exhibits robustness against measurement noise and scalability for large-scale networks. Ultimately, integrating the proposed localization method into the smart irrigation system has the potential to achieve approximately 28% reduction in water consumption.