Black’s pawn has run to h2 and it is checking White’s king on g1. The pawn is one square away and nothing is guarding it, so White plays 1.Kxh2, and a game that looked lost is a dead draw.
2
g Capturing the checking piece is one of the three legal answers to a check, alongside moving away and blocking the line. Nothing says the capture has to be made by a knight or a rook. Your king can do it himself, and in an endgame he often has to.
Only when the checker is undefended
Move Black’s king from d5 to g3 and the same capture disappears. The pawn on h2 is now protected, so Kxh2 would put White’s king on a square the black king attacks, and that is illegal.
2
g Note what happens there. White cannot take, cannot block a pawn check, and 1.Kf1 loses to 1…h1=Q. The one move that holds is 1.Kh1, standing in front of the pawn so it can never promote. Every strong player knows that position by heart, and it is worth twenty minutes of your time.
The check your king can never take
A knight. Not once, not ever. A knight’s move always ends on a square that is not adjacent to where it started, so a knight giving check is at least two squares from your king, and a king covers one square a turn. You also cannot block it, since there is nothing in between to block.
That leaves exactly two answers to a knight check: move the king, or capture the knight with another piece. Take both away and you have smothered mate, the prettiest mate in chess and the reason it works.
Two checkers, one answer
Double check, where a piece moves and uncovers a second attacker behind it, is the other case with only one answer: the king must move. He is allowed to capture one of the two attackers on the way, if the square is safe afterwards, but that is rare, because the piece he is not taking is usually still aiming at him. Double check is the strongest tactic there is for exactly this reason.
So when you are checked, run through the list in order. Can I take it? Can I block it? Where can the king go? Three questions, in that order, and check stops being frightening.