Blockchain, combination of blocks and chains is a type of digital ledger that can store data and transaction for the lifetime and the stored data is immutable (unchangeable), but the question here arises: Thousands of strangers sitting in every part of the world how do even agree that data stored is correct?
The answer to this question is given by consensus mechanism! Imagine there are 30 students in the class and the teacher wants to organize a picnic for them. So she asks everyone for their consent. What if only a group of students want to go so they lie to the teacher that every single one of the students has agreed upon going? In this situation, issue is solved by developing a system giving everyone individual right to vote which is visible to everyone (called consensus mechanism in terms of blockchain). No student can lie now! This solves the issue of trustless-ness among everyone.

There are actually many ways that can be used to introduce consensus mechanism. Very classic of these is Proof of Work (PoW). Take it as a class where the teacher announces whoever student solves the sum of 1-100,000 (which takes very much time), will get the chocolate as a reward and his work will be displayed on leaderboard. Now every student (miner, in terms of blockchain) starts solving this calculation by trying different combinations of numbers (called nonce) until it matches the actual answer (hash). Whoever solves it first will get its block added to the blockchain and will get the reward in the form of bitcoin as well. This process is called mining. It is the most secure method because it takes a lot of calculation and verification to add a block hence no chance of adding false information in the block. But here’s the catch! It uses a large amount of electricity. As much as used by some countries like Finland! Another issue is that it takes a lot of time (at least 10 minutes). This method was the reason blockchain became famous but now it is considered costly.
To overcome these issues, Proof of Stake (PoS) method was introduced. In this method you stake you crypto coins in your account (similar to depositing your money in a bank account). In this method not every miner from the network is required to use electricity and try to solve the calculation in competition. Instead the more coins in the account, the more the chance to become a validator (the one who adds the block to blockchain). It reduces amount of electricity used by 99% as compared to PoW. Where PoW takes 10 minutes, PoS take only 12 seconds in case of Ethereum (type of crypto coin) and 400 milliseconds in case of Solana. But if you try to make double transaction in PoS (fraud) some of your amount from your staked coins will be deducted as penalty. Which makes it secure along with speed and environment friendly.

Another method is Proof of History (PoH). In this method timing at which transaction made is recorded exactly as it is. But it is not a method in itself instead it is a time stamping tool only made by Solana. PoH is not even famous in networks other than Solana.
Many people think in blockchain you don’t have to trust anyone because it is “decentralized”, But here’s the plot twist: Blockchain is not completely trustless, in fact it distributes trust into whole network instead of a single entity. Here you trust on “code” not on humans.
So in short, consensus mechanism is the “working engine” of the blockchain. Blockchain doesn't ask you to trust a stranger it asks you to trust the math that keeps every stranger honest!