Most production systems do not roll their own election. They lean on a consensus algorithm, usually Raft or Paxos, or they delegate the whole thing to a coordination service like ZooKeeper or etcd.
In Raft, every node starts as a follower. Each node runs a randomized election timeout, typically 150 to 300 milliseconds. If a follower hears nothing from a leader before its timer fires, it becomes a candidate, increments the term number, votes for itself, and asks every other node for a vote. A node grants its vote to the first candidate it sees in that term, as long as that candidate's log is at least as up to date as its own. Whoever collects votes from a majority of the cluster wins and starts sending heartbeats. The randomized timers make it unlikely that two candidates start at the exact same instant, which is how split votes are avoided.
The majority rule is the heart of it. Requiring more than half the nodes to agree means two different leaders can never both win, because two overlapping majorities are impossible in a single cluster. This is also why these systems run an odd number of nodes, usually 3 or 5. A leader holds its position by sending heartbeats; the moment those stop, followers time out and a fresh election begins.
When you use ZooKeeper or etcd instead, you piggyback on their primitives. A common pattern is to have each node create an ephemeral sequential node, and the one with the lowest sequence number is leader. If that node's session dies, ZooKeeper deletes its ephemeral node automatically and the next-lowest node becomes leader.