The precise localization of sensor nodes is a key link in underwater wireless sensor networks (UWSNs) applications. Furthermore, the nodes in UWSNs should be able to independently determine their relative positions before they begin to receive and transmit data to each other. Most of the existing underwater localization algorithms are based on the anchor nodes with known locations, and the rest of the nodes can be calculated by the anchor nodes. The iterative localization process has been proposed for the localization of UWSNs, in which some positioned nodes as reference nodes are selected for iterative localization. However, in real scenarios, some anchor nodes may be destroyed naturally or artificially damaged or even used to convey misleading information to interfere with the precise localization of other nodes underwater. This paper proposes a computationally efficient localization algorithm that can accurately locate the sensor nodes underwater to resist such network attacks. The proposed algorithm achieves better localization accuracy by iteratively removing misleading information transmitted from interfering nodes based on the Time Difference of Arrival ranging mapping and combining selective minimum gradient of AdaDelta gradient descent (AGD). The simulation results prove that the proposed algorithm performs better under network attacks than the existing algorithms.