Wireless ad hoc and sensor networks, one of the important components of the Internet of Things, consist of hundreds or even thousands of tiny sensor nodes without a fixed infrastructure. Due to lack of transmission power, the presence of obstacles, and other environmental conditions, ordinary sensor nodes that are powered from their batteries may have to send data in a multi-hop manner to the sink node. Therefore, it is very important to conduct an energy-efficient and fault-tolerant routing algorithm. Clustering is one of the most popular methods for routing in wireless sensor networks. With the help of clustering, nodes are classified as cluster leaders and ordinary nodes. In this study, a distributed, fault-tolerant cluster leader selection algorithm is proposed for a wireless sensor and ad hoc networks that can be modeled as a unit disk graph. The proposed algorithm is self-stabilized and it is based on a maximum independent set. The theoretical analysis of the proposed algorithm is performed, it is implemented in SimPy environment and compared with other algorithms. According to the measurements taken, the proposed algorithm performs significantly better than its counterparts.