Black’s king on e8 is in check from the rook on e1. Four moves get him out: Kd7, Kd8, Kf7, Kf8. The move almost every beginner reaches for, Ke7, is not a legal move at all, because the king would still be sitting on the e-file with the rook staring at him.
e
f Article 3.9 of the Laws puts it in one line: no piece may be moved that leaves or places its own king in check. Not the king, not anything else, not even for one move.
Three ways players break it
Stepping back along the line, as above. A check from a rook or a queen covers the whole file or diagonal, so retreating in a straight line from it is no escape. Step off the line instead.
Capturing a defended piece. This is the expensive one, because the piece looks free.
8
Moving a piece that was shielding the king. Your bishop on e2 sits between your king on e1 and a black rook on e8, and you spot a lovely square for it on b5. You cannot play it. That bishop is pinned, and a pinned piece cannot move off the line even though nothing in the rules mentions the word pin: the move would leave your own king in check, and that is enough.
The rule counts attackers that cannot move
Here is the clause that surprises people. A square counts as attacked even if the piece attacking it could not legally go there, because moving would expose its own king. So an enemy bishop that is pinned stone dead still takes squares away from your king, and a pinned knight still stops you castling through the squares it covers.
The reverse also holds, which is why a king can never take a king: each one attacks all eight squares around it whether it can move or not.
What happens if you play it anyway
Online, nothing. The board refuses the move and you try something else, which is why so many players reach their first tournament having never seen this enforced.
Over the board, the position goes back to what it was, you make a legal move with the same piece if you can, and in a standard FIDE game the arbiter puts two minutes on your opponent’s clock. A second illegal move loses the game. In blitz it is harsher still: your opponent can claim the win on the first one. So before you play a king move, ask what covers the square. Then look again for the three legal ways out of check, and watch out for pins, which is the tactic that turns this rule into lost material.