How do nodes agree on a single version of the blockchain?

Every honest node runs the same consensus rules and checks each block for itself, so they all reach the same verdict on what is valid. When two miners find a block at nearly the same time, nodes resolve the tie by following the chain with the most accumulated proof-of-work; as soon as one branch gets the next block, every node switches to it and abandons the other. Because all nodes apply identical logic to identical data, agreement falls out naturally without any vote or central coordinator. This is also why a fresh block is not final until a few more blocks build on top of it.