Consensus algorithms are procedures through which all nodes in a network reach a common agreement about the current state of the distributed ledger.
Blockchain is a decentralized network maintained by a network of nodes (miners or validators). Every node has its own copy of the blockchain and to maintain the same state of the blockchain across the network we need a consensus mechanism. The general working of a consensus algorithm is shown below.