Three ways out of check
Move the king to a square that is not attacked.
Capture the piece that is giving check.
Block the check by putting a piece between the king and the attacker. This works against queens, rooks and bishops, but not against a knight or a pawn, which cannot be blocked.
If two pieces give check at once, called double check, only a king move can help, because you cannot capture or block both attackers in one move.
Checkmate
Checkmate is check with no legal escape. It ends the game immediately, whatever the material count. You never actually capture the king.
A few patterns appear again and again: the back-rank mate, where a king is trapped behind its own pawns; the smothered mate, where a knight mates a king surrounded by its own pieces; and the scholar's mate, a queen and bishop attack on f7 or f2 in the first few moves.
You may never put your own king in check
A move that leaves your own king attacked is illegal. That includes moving a piece that is pinned to the king, and moving your king next to the enemy king.